Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Functional programming in REBOL

From: lmecir:mbox:vol:cz at: 7-Aug-2001 11:00

Hi Larry, a few notes: ...snip...
> Let's create a partial application > function, pa. pa is a function factory (i.e., it makes functions for us). > This function needs to satisfy the following identity. > > ((pa f x) y) = (f x y)
...snip... The problem with the above is, that it is a Scheme expression. In Rebol we would have to say (do (pa :f :x) :y) = (f :x :y) , but there are cases, when even this is unsatisfactory, cf. my "mumblings" on UNSET! datatype, functions with unevaluated/fetched arguments, ... ...snip...
> create a function which will > automatically create functions that "remember their arguments" when
> My current version of this function is called cfunc indicating "context > func" or "closure func". If anyone sees a shorter or more elegant way to > write this function, please post.
...snip... In I call such a function E-FUNC. The difference is, that E-FUNC is neither shorter, nor more elegant, but "more general" in some aspects, e.g. it supports datatype checking and doesn't have trouble with "active arguments" like functions, words, paths, ... ...snip...
> Use of these functions with REBOL operators is hampered by the fact that
> with any of the characters [/ < >] cannot be accessed as set- or lit-
> I solved this with the function op which returns the value of the operator > given as an unevaluated word.
Not exactly, your OP function doesn't take an operator as an unevaluated word, it rather fetches the value, i.e. the X value your function below gets is not a word, it is an OP! value:
> op: func [:x][:x] ;how does it work? > > Now we can say > > >> mod5: pa-y op // 5
...snip... BTW, I don't like this kind of functions (out of the frying pan and into the fire, see my "mumblings" on unevaluated arguments etc. above). I would write: mod5: pa-y get first [//] 5 , which looks more readable to me.
> Now, at last, it's puzzle time ;-) Actually two puzzles. We note that pa > itself is a function of 2 arguments and therefore pa can be applied with > itself as the function arg and with itself as the value arg: > > mystery: pa :pa :pa > > What does the function mystery do? > > hmm: uncurry :curry > > What does the function hmm do?
...snip... Nice puzzles.