Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Oz

Name: Anonymous 2011-10-12 14:21

In OZ there is a function called map, which allows you to manipulate each member of a list and create a new list.

Map [1 2 3 4 5] fun {$ X} [X+1] end

This will add one to each element of the list and create a new one. Which would leave me with

[2 3 4 5 6]


I am trying to do something where I compare each element of the list to a Key and then print it if it matches, else nil.

I can't figure a way to get the variable Key into the anonymous function, as it will just declare a new instance. Is there a way to do this easily? Or am I trying to do this the wrong way.

Name: Anonymous 2011-10-12 14:29

I would want something like


fun{DoStuff List Key }

{Map List fun {$ X Key}  If X == Key then X else nil end end }
end


But when I do this, Key isn't bound to anything because it is declared in a new scope.

Name: Anonymous 2011-10-12 15:10

Oz is cool as fuck

IVE READ CTM.

Name: Anonymous 2011-10-12 15:15

I solved my problem, I didn't use map and just made my own function+helper function that appended things manually. It was a minor pain in the ass, so I would still like to know if using Map is possible.

Name: Anonymous 2011-10-12 15:35

I can't believe that there are actually people who use Oz.

Name: Anonymous 2011-10-12 15:58

>>4
Yes it is but I don't know the Oz syntax

Name: Anonymous 2011-10-12 16:05

>>5
If you haven't programmed in OZ you haven't achieved ``satori"

Name: Anonymous 2011-10-12 16:11

>>7
I guess I'm not a wizard of Oz yet...


Fucking ouch

Name: Anonymous 2011-10-12 16:31

>>8
that's kinda why it's called ``Oz''

Name: Anonymous 2011-10-12 17:40

>>2
You do not want Key as an argument in the inner function:
fun {DoStuff List Key}
  {Map List
       fun {$ X} If X == Key then X else nil end end}
end


Variables from the containing scope are available to the nested function. This is called a closure, and it's a very handy concept that you ought to learn to wield.

It is very useful for higher order programming. E.g.:
fun {MakeAdder N}
  fun {$ M} N + M end
end

This will return a function that can be applied to another number to add N, e.g.
{Show {{MakeAdder 1} 2}}

Name: Anonymous 2011-10-12 17:56

>>9
I thought it was because just when you least expect it, Beecher rapes you in the ass.

Name: Anonymous 2011-10-12 18:17

>>10
So how would I use MakeAdder operate on all the elements in a list?


{Map [2 2 2 3] {{MakeAdder} 2}}

Name: Anonymous 2011-10-12 18:23

>>10
Topic-related content

*golfclaps*

Name: Anonymous 2011-10-13 5:06

>>9
that's why the joke is so bad, yeah

Don't change these.
Name: Email:
Entire Thread Thread List