Skip to content

Commit

Permalink
Return '' when just <nl> is provided to 'input'
Browse files Browse the repository at this point in the history
That's what Python does. Snek's behavior of returning None didn't match.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Dec 11, 2022
1 parent e693926 commit 5145e0e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions snek-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ snek_builtin_input(uint8_t nposition, uint8_t nnamed, snek_poly_t *args)
{
char in[2] = {0, 0};
int c;
snek_poly_t s = SNEK_NULL;
snek_poly_t s = snek_string_to_poly(snek_alloc(1));

while (nposition--) {
snek_poly_t arg = *args++;
Expand All @@ -34,12 +34,8 @@ snek_builtin_input(uint8_t nposition, uint8_t nnamed, snek_poly_t *args)
(void) nnamed;
snek_in_input = true;
while ((c = getchar()) != '\n' && c != EOF) {
if (snek_is_null(s)) {
s = snek_string_make(c);
} else {
in[0] = c;
s = snek_string_cat(snek_poly_to_string(s), in);
}
in[0] = c;
s = snek_string_cat(snek_poly_to_string(s), in);
}
snek_in_input = false;
return s;
Expand Down

0 comments on commit 5145e0e

Please sign in to comment.