Replies: 1 comment
-
We now have I think this replaces I'm also curious about for item of list
if match item
break with item
unless break
'not found' // more likely, throw or return or something for item of list
if match item
break with item
if break
console.log 'found', for.value I also think we should consider the for item of list
if match item
break with item
else
'not found' // more likely, throw or return or something item :=
for item of list
if match item
break with item
else
null // instead of getting an array of results
if item?
console.log 'found', for.value Note: if we for item of list
if match item
console.log 'found', item
break
else
console.log 'not found' |
Beta Was this translation helpful? Give feedback.
-
for.value
For loop expressions, let's expose the array where values get accumulated, so you can add extra items, remove items, reset the entire value, etc. This gives you pretty full control on adding items within the loop.
for.value
,while.value
,until.value
,loop.value
,do.value
to access the value from the nearest ancestor loop of the given typefor:label.value
and maybe:label.value
to get the value of a labeled loopfor:label item of list
as more symmetric alternative for:label for item of list
for.push
forfor.value.push
results
object:results
object to something other than[]
:=
or.=
)Open question: Would
if.value
be useful to access the argument toif
? Maybe not, as that seems pretty different (if
's argument instead of return value).Postfix clause
We still would like control on the loop's value at the end of the loop. We could support a postfix clause that always runs at the end. I think
then
is a decent name. (It's liketry
'sfinally
clause, butfinally
clauses get run not returned, sothen
seems like a better name.)Admittedly, this example could also be written as
or more generally with pipe syntax:
So this feature may not be important. The next one is more interesting.
Postfix conditionals
It's common (e.g. in Python) to distinguish whether the loop
break
ed or not. We propose a postfix conditional usingbreak?
to enable distinguishing. More generally, allow assigning abreak.value
viabreak = ...
, similar to #361.Perhaps more interesting when we're not accumulating a
results
array:I think we only want to a conditional after a loop as a postfix conditional when it uses
break?
orbreak.value
. Otherwise, we'd get surprising results where we build and even return theresults
array but just expected a regularif
/else
expression:break
setsbreak.value
totrue
break = value
setsbreak.value
tovalue
if
/unless
when they usebreak.value
orbreak?
(shorthand forbreak.value?
)(transcribing last night's conversation with @STRd6)
Beta Was this translation helpful? Give feedback.
All reactions