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

Idiomatic Rebol

 [1/4] from: emekamicro:gm:ail at: 2-Sep-2010 18:34


Hello All, Please check if the below is idiomatic Rebol my-last: func[series][ if empty? next series [return first series] my-last next series ] my-but-last: func [series] [ if empty? next next series [return series] my-but-last next series ] element-at: func[series n m][ if n = m [return first series] element-at next series n add 1 m ] element-wat: func [series n][ element-at series n 0 ] reverse-list: func [series new-series][ if empty? series [return new-series] reverse-list next series join to-block first series new-series ] count-list: func [series n][ if empty? series [return n] count-list next series add 1 n ]

 [2/4] from: dhsunanda:gm:ail at: 2-Sep-2010 20:33


Good game! I've not looked at them all -- perhaps other will. But the last two are easily replaced by standard REBOL functions:
> reverse-list: func [series new-series][ > if empty? series [return new-series] > reverse-list next series join to-block first series new-series > ] >
Just use REVERSE: reverse [1 2 a print] == [print a 2 1]
> count-list: func [series n][ > if empty? series [return n] > count-list next series add 1 n > ] >
Just use LENGTH?: length? [1 2 a print] == 4 Check out the dictionary of REBOL words for other things you can do with a series: http://www.rebol.com/docs/dictionary.html Sunanda.

 [3/4] from: emekamicro:gma:il at: 2-Sep-2010 20:47


Sunanda, I am just solving exercises on http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html, using it to learn Rebol. I do know that we have those words, but I have to have a means of learning. Regards, Emeka On Thu, Sep 2, 2010 at 8:33 PM, Sunanda <dhsunanda-gmail.com> wrote:

 [4/4] from: dhsunanda:g:mail at: 2-Sep-2010 23:23


Emeka wrote:
> I am just solving exercises on
Interesting set of problems. Some will be one-worders -- using built-in REBOL functions. Some will be a little trickier. Many can be approached in two quite distinct ways: 1. threading together REBOL functions to solve the problem 2. using the PARSE dialect. Mastering PARSE may take your REBOLling to a new level. Do drop by here regularly to share solutions; I am sure the true gurus will be only too happy to chip in with tweaks and improvements. It could turn into a useful showcase for REBOL idioms. Good luck! Sunanda.