2

While comparing functional expressions in Clojure side-by-side with Rebol, I happened onto this expression from the examples of apply used in combination with map, at clojure-docs.org:

user=> (map #(apply max %) [[1 2 3] [4 5 6] [7 8 9]])
(3 6 9)

What is the most similar expression Rebol?

Adrian
  • 741
  • 4
  • 14

3 Answers3

4

Perhaps:

map-each x [[1 2 3] [4 6 5] [7 8 9]] [apply :reduce [first maximum-of x]]

But you don't need to use apply here:

map-each x [[1 2 3] [4 6 5] [7 8 9]] [first maximum-of x] 

NB. Notice that I changed middle list to [4 6 5]. This is important because...

maximum-of [4 6 5]   ; => [6 5]

Which isn't the same as max in Clojure (which returns highest number found in list).

draegtun
  • 22,441
  • 5
  • 48
  • 71
  • `maximum-of [4 6 5] ; => [6 5]` looks like a bug in Rebol. – Adrian Apr 16 '13 at 20:56
  • The relevant bugs are [#1971](http://curecode.org/rebol3/ticket.rsp?id=1971) and [#1972](http://curecode.org/rebol3/ticket.rsp?id=1972). – Adrian Apr 16 '13 at 21:03
  • 1
    No it's not a bug but it is badly named! According to docs `maximum-of` - *Finds the largest value in a series* & *Return the series at the position of its maximum value* (http://www.rebol.com/docs/words/wmaximum-of.html). The links you provided are *sugs* for better nomenclature for use in Rebol3. – draegtun Apr 16 '13 at 21:31
  • Hey awesome! 15.3k points and you know Rebol? You must come chat in the [Rebol and Red room](http://chat.stackoverflow.com/rooms/291/rebol-and-red) where we are scheming the open-source Redbolution...! :-) – HostileFork says dont trust SE Apr 16 '13 at 21:43
  • 1
    @HostileFork - I'm still kicking the tyres with Rebol so my knowledge is still very raw! Rebol only first grabbed my attention at the announcement of R3 being opensourced (end of last year). It is certainly a interesting and fun language to learn. It reminds me a lot of Io (which been playing with on/off for last few years). However unlike Io I can see the possibility of using Rebol in some *real life* stuff and the opensourced R3 will give it even more legs! So *Viva the Rebolution* and you may see me pop into the chat room now and again :) – draegtun Apr 17 '13 at 09:05
  • @draegtun Very cool...I [discovered it a while ago](http://hostilefork.com/2008/09/08/is-rebol-actually-a-revolution/) and walked away when progress stalled...now that it's open source I'm back. I designed [the new logo](http://hostilefork.com/2013/01/11/logo-design-for-rebol/) and am infamous for creating the Code Golf dialect [Rebmu](http://hostilefork.com/rebmu/). The PARSE dialect is absolutely killer in R3, so come chat and let us and RebolBot blow your mind! – HostileFork says dont trust SE Apr 18 '13 at 19:42
1

A similar expression in Rebol would be:

>> map-each x [[1 2 3] [4 5 6] [7 8 9]] [apply :reduce maximum-of x]
== [3 6 9]
Adrian
  • 741
  • 4
  • 14
  • 2
    Less similar to the original expression, but maybe interesting nevertheless: `collect [foreach x [[1 2 3] [4 5 6] [7 8 9]] [keep maximum-of x]]` – earl Apr 16 '13 at 20:29
0
map-each x [[1 2 3] [4 5 6] [7 8 9]] [first  maximum-of x]
john
  • 1
  • 2
    Can you please provide a little explanation of why you answer is an answer. thx! – kgdesouz Jul 13 '13 at 04:05
  • @kgdesouz Since maximum-of returns the *series* from the point of maximum value, first gives the first value in that return series which is a single value. – grantwparks Jun 21 '15 at 04:53