REBOL Assign command.
[1/8] from: edanaii::cox::net at: 28-Dec-2002 9:03
All,
I don't know if this has ever been done, so I did it myself. Created
something similar to the Assign command on the Amiga. Here is the code:
==========
REBOL []
Assign: Func [ "Creates an Amiga-like Assign command."
Volume [ Word!] "The function that this
command will create."
Path [ String! File! ] "The directory path that will
be assigned to it"
] [
Do Rejoin [ Volume ": Func [ AssignPath ] [ Return to-file Join %"
Path " AssignPath ] " ]
]
==========
It creates another function that returns the path specified when called.
So, for example, to create an Assign to locate REBOL Source code:
ASSIGN 'REBSOURCE C:REBOL/SOURCE
I can then call it to get source files:
DO REBSOURCE HOWDY.R
But if I call it to read a directory, I still need to pass a parameter.
READ REBSOURCE "."
This is slightly cumbersome.
So, all that being said, is there a way to make parameters optional in
REBOL? So far, in my meager investigations, I have not found a way. I'd
like to complete the function so that it can be called like this: READ
REBSOURCE, no parameters.
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
[2/8] from: amicom:sonic at: 28-Dec-2002 9:14
Ed,
You can specify optional parameters. But it can cause confusion inside a
script unless you specify the bounds of the evaluation (like inside a block).
>> rebsource: func [dir [any-type!]][if value? 'dir [print dir]]
>> rebsource
== none
>> rebsource "."
.
>>
Have fun!
Bohdan "Bo" Lechnowsky
Lechnowsky Technical Consulting
At 09:03 AM 12/28/02 -0700, you wrote:
[3/8] from: greggirwin:mindspring at: 28-Dec-2002 11:32
Hi Ed,
ED> So, all that being said, is there a way to make parameters optional in
ED> REBOL? So far, in my meager investigations, I have not found a way. I'd
ED> like to complete the function so that it can be called like this: READ
ED> REBSOURCE, no parameters.
In addition to Bo's comment, you could build your function to take a
refinement if that seems less cumbersome in your common use.
Assign: Func [
"Creates an Amiga-like Assign command."
Volume [ Word!] "The function that this commmand will create."
Path [ String! File! ] "The path that will be assigned to it."
] [
Do Rejoin [
Volume
": Func [/with AssignPath] [to-file Join %"
Path
{ either with [AssignPath][""] ] }
]
]
Then you would use it like this:
read REBSOURCE
do REBSOURCE/with %hello.r
-- Gregg
[4/8] from: edanaii:cox at: 28-Dec-2002 13:00
Excellent! Thank you Bohdan!
Here's the updated version:
==========
REBOL []
Assign: Func [ "Creates an Amiga-like Assign command."
Volume [ Word!] "The function that this
command will create."
Path [ String! File! ] "The directory path that will
be assigned to it"
] [
Do Trim Rejoin [ Volume {: Func [ FilePath [ Any-Type! ] ] [
Return Either (Value? 'FilePath) [
to-file Join %} Path { FilePath ] [
%"} Path {" ]
] }
]
]
==========
Much more useful now. :)
Bohdan or Rosemary Lechnowsky wrote:
> Ed,
> You can specify optional parameters. But it can cause confusion
<<quoted lines omitted: 7>>
> >>
> Have fun!
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
[5/8] from: rotenca:telvia:it at: 28-Dec-2002 22:31
> I don't know if this has ever been done, so I did it myself. Created
> something similar to the Assign command on the Amiga. Here is the code:
> So, for example, to create an Assign to locate REBOL Source code:
> ASSIGN 'REBSOURCE C:REBOL/SOURCE
>
> I can then call it to get source files:
> DO REBSOURCE HOWDY.R
Why not:
>> REBSOURCE: %/C/REBOL/SOURCE/
== %/C/REBOL/SOURCE/
>> REBSOURCE/howdy.r
== %/C/REBOL/SOURCE/howdy.r
---
Ciao
Romano
[6/8] from: nitsch-lists:netcologne at: 28-Dec-2002 22:34
Ed Dana wrote:
> All,
>
> I don't know if this has ever been done, so I did it myself. Created
> something similar to the Assign command on the Amiga. Here is the code:
I may frustrate you, but rebol has assigns inbuild.
if you do
rebsource: %/c/rebol/source/
you can write
do rebsource/howdy.r
unfortunally there is no direct way to specify dirs, because of rebol-syntax
subsource: rebsource/subdir/ ; does not work
use
subsource: dirize rebsource/subdir
or
subsource: join rebsource %subdir/
to read a directory,
read rebsource/.
additinal hint:
rebsource: clean-path %./
gives the absolute path, so you can change directory after that.
[7/8] from: g:santilli:tiscalinet:it at: 29-Dec-2002 0:05
Hi Ed,
On Saturday, December 28, 2002, 5:03:07 PM, you wrote:
ED> So, for example, to create an Assign to locate REBOL Source code:
ED> ASSIGN 'REBSOURCE C:REBOL/SOURCE
ED> I can then call it to get source files:
ED> DO REBSOURCE HOWDY.R
>> rebsource: %/C/REBOL/Script
== %/C/REBOL/Script
>> rebsource/anamonitor.r
== %/C/REBOL/Script/anamonitor.r
>> file: %anamonitor.r
== %anamonitor.r
>> rebsource/:file
== %/C/REBOL/Script/anamonitor.r
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[8/8] from: edanaii:cox at: 29-Dec-2002 8:17
Volker Nitsch wrote:
> Ed Dana wrote:
>> All,
<<quoted lines omitted: 6>>
> you can write
> do rebsource/howdy.r
You mean I wrote this for nothing??? :)
Well, actually, not nothing. I learned two things from this exercise:
how to make parameters optional and that the file datatype is more
flexible than I realized. :)
Very good. Thanks all.
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted