[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
In ll1-discuss Paul Prescod writes:
>Also, it is debatable what the "right thing" for an expression like this
>to return is:
>k = while foo():
> print "abc"
> print "def"
> print "ghi"
>I guess it would return None (Python's nil/null thing)? Allowing people
>to assign the results of a while loop just seems obfuscatory and thus
>un-pythonic.
One of the things I found interesting about the Icon programming language
when I did some things with it several years ago was that, unlike most other
languages I'd seen, things that in other languages were statements, like while
loops, were expressions in Icon. As you suggest, while doesn't actually
return anything interesting, just a null, as we can see from the following
example:
32 ichotolot /tmp[ 8:41PM] Z% cat foo.icn
procedure main()
local foo, i
i:=0
foo := while(i<5) do {
i +:= 1
write(i)
}
write("============")
display()
end
33 ichotolot /tmp[ 8:41PM] Z% ./foo
1
2
3
4
5
============
co-expression_1(1)
main local identifiers:
foo = &null
i = 5
global identifiers:
display = function display
main = procedure main
write = function write
The display() function dumps the current state of all local and global
variables; as we can see, the assignment of the value from the while loop
set foo's value to null.