r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3-OLD1]

Volker
10-Feb-2007
[1929]
a:+ is  already an url.
Pekr
10-Feb-2007
[1930]
Geomol - your function posted in blog works without the set-word, 
so why you needed it to work via a set-word?
Geomol
10-Feb-2007
[1931x2]
Because:

>> mult2: func [value] [value * 2]
>> a: 3
>> mult2 a
== 6
>> a
== 3

a isn't changed.
If ++/-- are introduced, they'll change a this way:

>> a: 3
>> ++ a
== 4
>> a
== 4
Pekr
10-Feb-2007
[1933]
ah, I see ...
Geomol
10-Feb-2007
[1934x2]
My argument is, that if something like ++/-- are introduced in the 
language, I as a programmer would expect, that I can make my own 
++/-- like functions very easily.
I keep thinking about operators (of type op!). It's not possible 
to make new operators in REBOL afaik. Why not? Can we come up with 
an easy way to make new user-defined operators?
Pekr
10-Feb-2007
[1936]
I don't need such functions. IMO operators already break rebol left 
to right evaluation. IMO it only will cause more confusion. INC a, 
DEC a, is imo much more rebolish.
Volker
10-Feb-2007
[1937]
Its not possible because  Carl hardwired them in r2. AFAIK its posible 
 in r3.
Pekr
10-Feb-2007
[1938]
Volker - how do you know? :-)
Volker
10-Feb-2007
[1939]
Because in some chat  somewhere Carl hinted it. IIRC  and  all.
Geomol
10-Feb-2007
[1940x6]
Maybe something like:

>> root: operator [arg1 arg2] [arg1 ** (1 / arg2)]
>> 27 root 3
== 3


This define root as an operator, which will calculate a given root 
of a value. The 3th root of 27 is 3, because 3 * 3 * 3 = 27
Or maybe the operator should be defined the other way around, so 
I should write:

>> 3 root 27
But is it REBOLish? :-) Like Pekr is concerned with. REBOL is a different 
language. It's more of a human language than a computer language. 
I think, a key to decide the structure of the language is to look 
at the sentences, it's possible to write with the language, and then 
see if those sentences makes sense and are easy to read and understand.
Today I can define root as a function:

>> root: func [arg1 arg2] [arg1 ** (1 / arg2)]

and use it:

>> a: root 100 3
== 4.64158883361278


The question is, if it will be better to be able define root as an 
operator and then write:

>> a: 100 root 3
== 4.64158883361278
We can also look at it this way:

Anything is possible in dialects. It's possible to make a dialect 
parsing a block, where I can use root as an operator. If it's possible 
in a dialect, why shouldn't it be possible directly in the language? 
Of course it's then easier to make code hard to read and understand, 
but that's possible today with dialects. Will we as developers have 
the freedom to do almost anything, and then it's up to us to develop 
code easy to read and understand, or will we like restrictions? If 
the freedom is used the right way, it's also easier to develop code, 
that IS easier to read and understand.


My point of view is, that when the language has operators, it should 
be possible to make our own operators too.

If ++/-- are introduced, it should be possible in an easy way to 
make our own functions working the same way.
Actually we're already used to the way INC/DEC would work, just with 
other datatypes. If I wanna sort a series, I e.g. write:

>> blk: [3 5 2]
>> sort blk
== [2 3 5]
>> blk
== [2 3 5]


The block is changed directly by the sort command (function). Without 
this mechanism, I would have to write:

>> blk: sort blk

In this regard, it makes very much sense to be able to write:

>> a: 4
>> inc a
== 5
>> a
== 5
Gabriele
10-Feb-2007
[1946x2]
Geomol: your arg: suggestion can't work. (to say it another way: 
it would require very deep changes to rebol)
also, how is that different from using a 'arg and set?
Geomol
10-Feb-2007
[1948x6]
Everything should be made as simple as possible, but not simpler.

I prefer
mult2: func [value:] [value * 2]
over
mult2: func ['value] [set value (get value) * 2]

Also the former might be able to handle
mult2 4

, where the latter gives an error. So using today REBOL, I need to 
handle different datatypes in my function. But if it requre deep 
changes, maybe it should be left out.
require
A function being able to handle numbers and words (holding numbers) 
might be (in today code):

mult2: func ['value] [
	either number? value [
		value * 2
	][
		set value (get value) * 2
	]
]

Just doing:
mult2: func [value:] [value * 2]

is much easier.
The operator
*
works with Type: number pair char money time tuple

We have to check for all those, when defining a mult2 function today. 
(Or catch the error.)
Ah, it might be sufficient to check for word!:

mult2: func ['value] [either word? value [set value (get value) * 
2] [value * 2]]
A function increasing something by 2, which can handle direct values 
and words holding values and series, today have to be something like:

inc2: func ['value] [
	either word? value [
		either series? get value [
			set value skip get value 2
		][
			set value (get value) + 2
		]
	][
		value + 2
	]
]

With set-word arguments, it might be:

inc2: [value:] [
	either series? value [
		skip value 2
	][
		value + 2
	]
]

With INC, it could be:

inc2: [value] [inc inc value]


Maybe an increase function taking two arguments should be native 
too (like INC and DEC):

increase value 2


All these are just ideas to think about, when you guys create REBOL3.
Ladislav
10-Feb-2007
[1954]
Geomol wrote:

mult2: func ['value] [...]


as I said many times I am wholeheartedly against this nontransparent 
argument passing variant. I consider

mult2: func [value] [...]

always better than that
Gabriele
11-Feb-2007
[1955]
Geomol: again, what you ask for needs at least a couple new datatypes, 
and breaks the evaluation semantics... you may see it as "simpler" 
but i see it as a huge complication of the language (a useless one, 
too)
Geomol
11-Feb-2007
[1956x2]
Hm, maybe I didn't explain myself well enough. All this come from 
Carl's blog about ++/--. He writes

count: 0
++ count ; add one


I see ++ as a function with calling-by-reference. ++ isn't called 
with the value of count but with it's reference, so ++ can change 
the value of count. My point is, that if ++ is introduced in the 
language, it may be a good idea to implement a method, so programmers 
easily can make their own ++ kind of functions.

That's all.
And the other way around, if it isn't easily possible to introduce 
such a method (calling by reference), then it may not be a good idea 
to introduce ++/--.
Ladislav
11-Feb-2007
[1958]
the lit-argument passing method is already present in the language 
(although I am against it, to express my preferences, since ++ 'count 
looks good enough to me being referentially transparent - try to 
write ++ pick [a b] 1 using the nontransparent argument passing method), 
so you are indeed requesting much more than that complicating the 
languge without offering an advantage that would justify it
Volker
11-Feb-2007
[1959]
You can also not write your own 'do. IMO itis ok that  some things 
 are only possible at native level. Its  not  lisp.

inc/dec/shift are essential enough for speed and commodity, these 
could be an exception. (Maybe  evenn '<< and '>> as  operators, and 
allowed  in parser?)
Ladislav
11-Feb-2007
[1960]
as opposed to that, I guess that these cannot save much time anyway
Volker
11-Feb-2007
[1961x4]
four interpreter-steps instead of one? in a tight  search-loop?  
 until[pair? ++ blk]
btw i prefer post-increment.
but thats a rebcode-case anyway.
i dont like  the repitition when incrementing, moving. the two 'count. 
But  i have no good syntax :(
Gabriele
11-Feb-2007
[1965]
Geomol: as ladislav said, that method is already there. rebol does 
not have "by reference", so if you want passing "by reference" you're 
going to change the language a lot.
Geomol
11-Feb-2007
[1966x2]
Yes, I see.
I understand, why Carl is concerned, if he should include ++/-- or 
not. I don't think, we have something similar today working on scalar 
data types. An action like NEGATE doesn't change the variable holding 
the scalar data type:

>> negate 4
== -4
>> a: 4
>> negate a
== -4
>> a
== 4

So I bet it'll be confusing, if ++/-- does change the variable.
Izkata
11-Feb-2007
[1968]
What would this be called, then?  (I remember it came up before - 
I mean, what's this kind of variable passing called, if not "by reference" 
?)

>> ++: func ['X][set X (1 + get X)]
>> foo: 5
== 5
>> ++ foo
== 6
>> foo
== 6
Ladislav
11-Feb-2007
[1969x2]
another variant demonstrating the advantages of "transparent" argument 
passing:

++: func [x] [set x 1 + get x]
foo: 5
++ 'foo ; == 6
foo ; == 6
++ pick [foo bar] 1 ; == 7
foo ; == 7
Izkata: you cannot call it "by reference", since you are actually 
passing the value you are manipulating - the word, not a reference 
to it
Maxim
11-Feb-2007
[1971]
ladislav, that in C is just what a reference is... you pass not the 
value, but the pointer which refers to it... in REBOL that is a word. 
 under the hood, in REBOL everything really is a pointer to a value, 
with an offset within a context, no?
Ladislav
11-Feb-2007
[1972x2]
ladislav, that in C is just what a reference is

 - that looks like an error to me - references are in C++ actually. 
 Pointers are passed "by value" in C
in REBOL everything really is a pointer to a value, with an offset 
within a context, no?

 - you can explore how REBOL values look using my hints in this world 
 and at REP
Maxim
11-Feb-2007
[1974x4]
lad: a reference to a number is a common usage term which means get 
the pointer to the memory area where the number is contained... not 
the value at that pointer.  in C series variables have to be pointers, 
but numbers aren't usually pointers.  thus the reference to that 
number is its pointer.
if you pass the reference, and chance the value at that adress and 
change it in place... all "references" to it will change.
so I think you are both talking the same language, but with different 
terminology.... based on your usage of C..  :-)
(or C++)
Ladislav
11-Feb-2007
[1978]
what you are saying is terminologically misleading. "Pass by value" 
has got a broadly accepted meaning as well as "pass by reference". 
If you pass a pointer in C, then you pass it "by value" according 
to the definition.