Hi Jason,
<< It's kind of embarrassing, but I've forgotten the REBOL idioms for
something
really basic..
How to check for arguments provided to a function?
How to check when the argument is optional and when it is missing?
somefunc: func [arg1 arg2 ... argN] [
; check args here and respond
Hi Gregg
> Do you mean refinements?
..not exactly thanks, but your example taught me something handy:-)
>> somefunc: func [inp] [print [inp * 3.14159]]
>> somefunc 4
12.56636
>> somefunc
** Script Error: somefunc is missing its inp argument
** Near: somefunc
Q1: How to catch the missing param
On 09-Jun-02, Jason Cunliffe wrote:
> Hi Gregg
>> Do you mean refinements?
> ..not exactly thanks, but your example taught me something handy:-)
>>> somefunc: func [inp] [print [inp * 3.14159]]
>>> somefunc 4
> 12.56636
>>> somefunc
> ** Script Error: somefunc is missing its inp argument
> **
Hi Jason,
> >> somefunc: func [inp] [print [inp * 3.14159]]
> >> somefunc 4
> 12.56636
> >> somefunc
> ** Script Error: somefunc is missing its inp argument
> ** Near: somefunc
>
> Q1: How to catch the missing param so the script won't crash?
somefunc: func [inp [any-type!]] [if value? 'inp [pr
IL PROTECTED]>
Sent: Saturday, June 08, 2002 6:07 PM
Subject: [REBOL] Re: How to check function arguments ?
> On 09-Jun-02, Jason Cunliffe wrote:
>
> > Hi Gregg
>
> >> Do you mean refinements?
>
> > ..not exactly thanks, but your example taught me something hand
Hi Jason,
On Saturday, June 08, 2002, 10:10:10 PM, you wrote:
JC> Q1: How to catch the missing param so the script won't crash?
Well, there's a way, but I don't recommend it as it can create
more problems than it solves.
>> somefunc: func [inp [number! unset!]] [print either value? 'inp [i
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,
> >> somefunc print "done."
> done.
> no value passed
..yikes!
Gabriele that's a very good point. I guess it's back to the drawing board to
think about this some more. REBOL is so full of funny surprises.
cheers
./Jason
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTE
hmm..
Q: How to tell if a word already exists or if is just an argument value being
passed?
>> somefunc: func [inp [any-type!]][if value? 'inp [print inp "do stuff"]]
>> somefunc
== none
>> somefunc "hello"
hello
== "do stuff"
>> somefunc print now
9-Jun-2002/8:32:33-4:00
== none
When the input
Hi Jason,
On Sunday, June 09, 2002, 7:11:36 AM, you wrote:
JC> REBOL makes one work harder for the defaults. Perhaps you already know some more
JC> cool idioms ;-)
f: func [/opt optional-arg] [
optional-arg: any [optional-arg "default value"]
print optional-arg
]
Regards,
Gabriele.
Hi Jason,
On Sunday, June 09, 2002, 3:21:28 PM, you wrote:
JC> When the input to somefunc is something like 'print' or any word in the rebol
JC> dictionary, we might assume that it is not a valid argument. Arguments we would
JC> be expecting would usually be a number, a name, a time, a block, et
Hi Jason,
Jason Cunliffe wrote:
> hmm..
>
> Q: How to tell if a word already exists or if is just an argument value being
> passed?
>
>
>>>somefunc: func [inp [any-type!]][if value? 'inp [print inp "do stuff"]]
>>>somefunc
>>
> == none
>
>>>somefunc "hello"
>>
> hello
> == "do stuff"
>
>>>so
Hi Gabriele,
> JC> REBOL makes one work harder for the defaults. Perhaps you already know
some more
> JC> cool idioms ;-)
>
> f: func [/opt optional-arg] [
> optional-arg: any [optional-arg "default value"]
print optional-arg
> ]
But remember:
>> f/opt none
default value
>> f/opt false
On 09-Jun-02, Charles wrote:
> Easiest solution is like Romano said: Just use any-type! I use it
> in a die rolling CGI script, where you can do: roll?2d6
> or
> roll?2d6+3
> (or +-3)
> I also use:
> args: system/options/args
Ah - I didn't know of that solution. And I hadn't noticed that
>>? any
USAGE:
ANY block
DESCRIPTION:
Shortcut OR. Evaluates and returns the first value that is not FALSE or
NONE.
ANY is a native value.
ARGUMENTS:
block -- Block of expressions (Type: block)
any-type! is a suedo-type that includes any data-type!
HTH
Ammon
A short time
Hello Gabriele,
on Sunday, 09-Jun-02, 15:12:46, Gabriele Santilli wrote:
> REBOL does not support variable number of arguments because of its
> freeform syntax.
As with all rules there seems to be an expection:
The list of arguments to MAKE as specified by
>> source make
== make: nati
Hi Christian,
On Sunday, June 09, 2002, 11:44:37 PM, you wrote:
CE> As with all rules there seems to be an expection:
Indeed, there are some exceptions. Not only MAKE, but also DO;
they are likely to access the internal interpreter state to fetch
extra arguments when needed. It would be c
Hi Christian and all,
my essay http://www.rebolforces.com/~ladislav/argstake.html describes how
Rebol functions take their arguments. If you want to see some parsing
example, have a look at the APPLY function in
http://www.rebolforces.com/~ladislav/highfun.r
-L
- Original Message -
From
You can read:
http://www.rebolforces.com/~ladislav/argstake.html
---
Ciao
Romano
- Original Message -
From: "Christian Ensel" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 09, 2002 11:44 PM
Subject: [REBOL] Re: How to check function argument
Hi [Ladislav Romano Gabriele],
On monday, 10-Jun-02, 07:48:53, Ladislav Mecir wrote:
> my essay http://www.rebolforces.com/~ladislav/argstake.html describes how
> Rebol functions take their arguments.
Not that for one single moment I thought I've discovered a not so well-known
rebol behaviour .
Hi all,
some minor changes at my rebsite (see
http://www.rebolforces.com/~ladislav ), especially evaluation.html now
contains two possible definitions of recursive blocks.
-L
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without
21 matches
Mail list logo