Hi,
> I assume you meant:
>
> register 'minus [integer! complex!] [] [
> make complex [
> re: a - b/re
> im: - b/im ; not im: b/im
> ]
> ]
>
> Shouldn't the signatures look more like:
>
> signatures: [[integer! complex!] [complex! complex!]]
Yes, thanks.
> I'm also
Hi Ladislav,
You're system of functions is quite amazing. I'm trying to digest
what you're aiming at, little by little.
I assume you meant:
register 'minus [integer! complex!] [] [
make complex [
re: a - b/re
im: - b/im ; not im: b/im
]
]
I tried to register another
Oops!
Some errors during copying. The attachment needs a Title:
"Polymorphic" and the registration of [Integer! Complex!]
signature is:
register 'minus [integer! complex!] [] [
make complex [
re: a - b/re
im: b/im
]
]
Ladislav
#5 Polymorphic operators, only prefix notation supported :-(
Let us look at the following:
; currently alpha stage, trying to improve it, it is attached
do %polymorphic.r
complex: make object! [
type: 'complex!
re: im: 0
]
polymorphic [minus a b]
register 'minus [complex! complex!] []
Hi Ladislav,
I did some investigation of the datatype test functions, such as
NUMBER? and BLOCK? I found they always return a logic value, no
matter what type of argument they have - even if it's UNSET! or
ERROR! I put together a number of functions testing for what you
called "predicate types".
Hi Ladislav,
Except - doesn't work the same as SUBTRACT unless it's used as an infix:
>> bop - [3 2 1] [1 1 1]
== [-3 -2 -1]
I thought of providing special processing to switch SUBTRACT for - ,
but thought it would be more fun to use the operators as infixes.
Catch you later,
Eric
You w
#3 Forward Polymorphic vs. Backward Polymorphic
Well, the Solve code was meant only as an example of a more or
less working approach. There is a use for something "more
polymorphic" and "less polluting", IMHO.
Glad to see the interesting discussion.
About the C++ - like approach, where the oper
Actually, I'd like to have C++ overloaded functions in REBOL. Then adding
complex numbers and integers in any combination become a snap!
Andrew Martin
ICQ: 26227169
http://members.xoom.com/AndrewMartin/
-><-
Nice try, but it is only a more complicated version of:
bop: func [
{returns the results of operating on elements of b with those
of bb -
last element of bb will be reused if necessary}
'op [word!] "name of function to use"
b [block!]
bb
/local r
][
op: get in syst
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 25, 2000 5:24 PM
> To: [EMAIL PROTECTED]
> Subject: [REBOL] Polymorphic
> I do like this kind of polymorphism. It can be observed only when
> using the prefix binary operators.
>
> OTOH, I t
Hi Ladislav,
What do you think of this? It's sort of polymorphic, but it's not the
right approach to handle complex numbers.
bop: func [
{returns the results of operating on elements of b with those of bb -
last element of bb will be reused if necessary}
'op [word!] "name of f
Hi Ladislav,
You wrote:
>Sorry for disappointing you, but the proposed version doesn't
>handle correctly the computed blocks and Break. A different
>approach:
Actually you haven't disappointed me, because I didn't intend to
handle computed blocks, and BREAK seems to work as well as I'd hope
it
Sorry for disappointing you, but the proposed version doesn't
handle correctly the computed blocks and Break. A different
approach:
; a helper function
db: func [[throw] arg] [
either block? arg [do arg] [arg]
]
pif: func [[throw]
{polymorphic if, lazy evaluation, minimal checking}
a
[EMAIL PROTECTED] wrote:
>
> pif: func [
> [throw]
> {polymorphic if with lazy evaluation and minimal checking}
> args [block!]
> ] [
> while [not empty? args] [
> args: do/next args
> either all [
> not unset? first args
> first args
>
[EMAIL PROTECTED] wrote:
>
> With 'throw any 'return or 'exit will be passed along to the
> caller.
>
Thanks for the concise explanation! My brain has been hashing catch
and throw to their use in a LISP context all along, and I missed
this point.
-jn-
Hi Joel,
How about this variation of Ladislav's function?
pif: func [
[throw]
{polymorphic if with lazy evaluation and minimal checking}
args [block!]
] [
result: false
while [not empty? args] [
args: do/next args
either all [
Joel wrote:
> I have a general comment about this thread. It seems to me to point up
the difficulty of writing first-class control structures in REBOL. I haven't
seen in this thread (nor have I been able to think of) an approach that
actually behaves as well as a native control structure.
Yes. I
I have a general comment about this thread. It seems to me to point
up the difficulty of writing first-class control structures in REBOL.
I haven't seen in this thread (nor have I been able to think of) an
approach that actually behaves as well as a native control structure.
To illustrate this,
Hi, Ladislav, sorry for the terribly slow response.
[EMAIL PROTECTED] wrote:
>
> BTW, Joel, i liked your (NON)boring version of CC verify function
> description (I catched myself using some principles you
> diapproved - especially the code copying is really a drug
> sometimes...). Could you PLEA
Hi, I think, that a mix can easily be achieved as follows:
cases-dialect: make object! [
"Dialect for do-cases"
else-if: if: func [[throw]
condition
body [block!]
] [
system/words/if condition [body]
]
else: func [[th
Hi, one more version handling correctly Return and Exit.
pif: func [[throw]
{polymorphic if with lazy evaluation and minimal checking}
args [block!] /local cond blk r result
] [
result: false
while [not empty? args] [
either cond: first r: do/next args [
either
Hi, Anrew, it doesn't work in the case:
ifs [
false append/only copy [print] "Hi"
true [print first "hello"]
]
> ; Lazy evaluation of multiple 'if-s.
>
> Ifs: function [Ifs [block!] /Default Case [block!]] [Block] [
> while [not empty? Ifs] [
> Block: do/next Ifs
> i
Hi, in the case of your Ifs I would prefer this:
> print Ifs [
> X < 0 [-1]
> X = 0 [0]
> (0 < X) and (X < 10) [+1]
> true ["Much bigger!"]
> ]
>
> It's a lot like Ladislav's version.
>
> Andrew Martin
> ICQ: 26227169
> [EMAIL PROTECTED]
> http://members.xoom.com/AndrewMarti
; Lazy evaluation of multiple 'if-s.
Ifs: function [Ifs [block!] /Default Case [block!]] [Block] [
while [not empty? Ifs] [
Block: do/next Ifs
if first Block [return do first second Block]
Ifs: next second Block
]
if Default [return do Case]
none
]
[EMAIL PROTECTED] wrote:
> etc. (you get the idea)? So is it impossible to 'add' capabilities to "read"
> without "overloading" the word so it wouldn't be able to be used as it
> normally is? For instance, if I wanted to be able to say:
>
> read pnm://whatever-real-audio-file
Have a look at sy
On 7-Dec-1999/23:20:01-5:00, [EMAIL PROTECTED] wrote:
>For instance, I can use the word read for so many different things...
>reading from an ftp site, reading from a web page, getting a directory
>listing, reading a file, and on and on. Is there something internal in the
>read function that does
Hi Keith,
You can do this by creating your own port protocol handler for pnm or
audiobook in the same way as ftp and http are handled. This is done by
creating a port handler object and adding it to the system/schemes block.
Try doing a "probe system/schemes/finger" to see an example port handler
27 matches
Mail list logo