Skip to content

Commit

Permalink
- Modified the 'read()' built-in function.
Browse files Browse the repository at this point in the history
It no longer accepts variables references as arugments. Instead, it expects a type as the first argument, or a message as first argument and a type after the message.

Example:
	read(Number);		# reads a number
	read("name ", String);  # displays a message and reads a string

Also, on failure (or on CTRL+D), it will now return `nil`.
  • Loading branch information
trizen committed Nov 7, 2015
1 parent 146feea commit de7537b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
16 changes: 6 additions & 10 deletions lib/Sidef/Sys/Sys.pm
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,19 @@ package Sidef::Sys::Sys {
*readln = \&scanln;

sub read {
my ($self, $type, @vars) = @_;
my ($self, $type, $opt_arg) = @_;

if (@vars) {
foreach my $var_ref (@vars) {
chomp(my $input = <STDIN>);
${$var_ref} = $type->new($input);
}

return $self;
if (defined $opt_arg) {
print $type;
$type = $opt_arg;
}

if (defined $type) {
chomp(my $input = <STDIN>);
chomp(my $input = <STDIN> // return);
return $type->new($input);
}

chomp(my $input = <STDIN>);
chomp(my $input = <STDIN> // return);
Sidef::Types::String::String->new($input);
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/Interactive/integer_comparison.sf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
## http://rosettacode.org/wiki/Integer_comparison
#

read(Number, \var a, \var b);
var a = read("a: ", Number);
var b = read("b: ", Number);
 
if (a < b) {
say 'Lower';
Expand Down

0 comments on commit de7537b

Please sign in to comment.