Menu

#4 Implement `#` for blocks

0.6.1
fixed
aditsu
None
2014-07-09
2014-06-17
Dennis
No

In GolfScript, you can do this:

5,{3>}?

which is more or less equivalent to

5,{3>},0=

It would be nice if this worked with CJam's # as well.

Discussion

  • aditsu

    aditsu - 2014-06-18

    I'd like to do this, but I wonder how it should work. There are mainly 2 ways:
    1) Get the index of the first matching element, or -1 if not found. This would be consistent with the non-block usage, but different from GolfScript, and still longer if you actually want the value.
    2) Get the value of the first matching element, like GolfScript. In that case, what should happen if there's no match? I don't like how GolfScript just "returns void". Also, what if you wanted the index?

     
  • aditsu

    aditsu - 2014-06-18
    • assigned_to: aditsu
     
  • Dennis

    Dennis - 2014-06-18

    = is not implemented for ArrayList-Block, so you could use # for option 1 and = for option 2.

    Returning void is probably the best choice for option 2, in case you're building an array of matches for several different conditions. The only unambiguous alternative would be the array itself, but I doubt that would be useful.

     
  • aditsu

    aditsu - 2014-06-20

    That's a great idea! I think I'll do that.

     
  • aditsu

    aditsu - 2014-06-21

    Done, will be released in 0.6.2

     
  • aditsu

    aditsu - 2014-06-21
    • status: open --> fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.