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

[REBOL] Re: How to check function arguments ?

From: jason:cunliffe:verizon at: 9-Jun-2002 1:11

Hi Romano and everyone
> somefunc: func [inp [any-type!]] [if value? 'inp [print [inp * 3.14159]]]
..damn that's clever.. thanks! It's a very interesting idiom the way it depends upon those two quite different but crucial parts any-type! 'inp Doing quite a lot of Vanilla programming, so it's sometimes cgi, some times internal functions. But the more flexible the args, the better - you don't have to remember, and it makes modular API development easier. Before REBOL, I was in love with Python, which has some great features for function args: 1. Keyword arguments with defaults 2. - Variable Length arguments Here's an example from Core Python Programming by Wesley Chun [good book] def tupleVarArgs(arg1, arg2='defaultB', *theRest) 'display regular args and non-keyword variable args' print 'formal arg1:', arg1 print 'formal arg2:', arg2 for eachXtrArg in theRest: print 'another arg:', eachXtrArg When a double ** is used it signifies variable Keyword arguments [Python Dictionary]. Python dicts are close to REBOL blocks depending how you use them, so I guess variable keyword args could be done with a combination of REBOL's refinements and some other magic. REBOL makes one work harder for the defaults. Perhaps you already know some more cool idioms ;-) thanks ./Jason