• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[!REBOL3] General discussion about REBOL 3

Geomol
29-May-2013
[2496x5]
Continuing from #Red group. A johnk asked for multi-line source from 
Carl. This is my W_GETS code in World, which has multi-line (blocks 
and long strings). I don't know, if you can use it, as World might 
be different internal:

char prompt_str[]	= "prin system/console/prompt";
char block_str[]	= "prin system/console/block";
char string_str[]	= "prin system/console/string";

#define W_GETS \
	if (W->line_read) { \
		free (W->line_read); \
		W->line_read = NULL; \
	} \
	if (W->top_of_series > W->series_base) { \
		W->stack = W->stack + 1; \
		int trace = W->trace; \
		W->trace = 0; \
		if (*W->top_of_series == BLOCK_BEGIN_T) { \
			tv.newline = 1; \
			do_string (W, block_str); \
			int i; \
			for (i = 0; i < W->top_of_blocks - W->blocks; i++) \
				w_printf ("    "); \
		} else { \
			do_string (W, string_str); \
			w_printf ("    "); \
		} \
		W->trace = trace; \
		W->stack = W->stack - 1; \
	} else { \
		W->top_of_code = W->code - 1; \
		W->top = -1; \
		if (NULL != W->P) \
			printf ("**** W->P != NULL ****\n"); \
		W->stack = W->stack + 1; \
		int trace = W->trace; \
		W->trace = 0; \
		do_string (W, prompt_str); \
		W->trace = trace; \
		W->stack = W->stack - 1; \
	} \
	W->line_read = w_readline (&auto_brackets, &tab_completion); \
	reset_stack (W); \
	if (W->line_read == NULL) throw_error (W, ERRMEM_S); \
	if (W->line_read[0] == KEY_CTRL_D) throw_error (W, QUIT_S); \
	W->save_line_read = W->line_read;
Some exmplanation:


W->top_of_series is a stack holding the different types of series 
being entered in the lexer, defined as:

#define BLOCK_BEGIN_T		58
#define PAREN_BEGIN_T		59
#define LONG_STRING_BEGIN_T	60
#define PATH_BEGIN_T		61
#define GET_PATH_BEGIN_T	62
#define LIT_PATH_BEGIN_T	63
#define BINARY_BEGIN_T		64
#define SET_GET_PATH_T		65


The code about trace is just, if tracing is on or off in World. W->top_of_code 
is a pointer to where the code for the virtual machine in World is 
being created, and W->code is the bottom of that stack in instructions, 
W->top the top. do_string executes a string of World code.
stack *of* instructions
The line
	tv.newline = 1;

sets a newline in the block of code entered. tv is a Tagged Value 
in World, a value with type specification.
The printf ... W->P != NULL is just some debug code, that should 
be removed.
sqlab
29-May-2013
[2501]
as long as you are not inside a string you should also reagard comments
Geomol
29-May-2013
[2502]
I do that in World in the lexer, which parses W->line_read, that 
is being entered into with the code above.

w> b: [ 
[    ; a comment
[    "hello"
[    ]
== [
hello
]
w> ? b
b is a block! of value: [
    "hello"
]
w>
sqlab
29-May-2013
[2503]
what was again the shortcut for switching the enter mode ?
Maxim
29-May-2013
[2504]
CTRL-E  or the little pencil icon above text box
Geomol
29-May-2013
[2505x2]
sqlab, if you mean at the World prompt, it's ctrl-a
The source for w_readline is found here:
https://github.com/Geomol/World/tree/master/src/host
GiuseppeC
30-May-2013
[2507]
Hi,

  REBOL language differs from other languages because you can write 
  "human resembling" code lines.

  During the past weeks I have thought about a way to make more understandable 
  the language in a simple way

   now you can write:

   mypage: read http://www.rebol.com

    I whish to write:

    set the variable mypage: reading from http://www.rebol.com


    It is actually impossible to have this stile but if you add another 
    way of commenting it woul be possible. Lets assume we have a way 
    to start comments with "/*" and and comments with "*/"

    Now we can write


    /*set the variable*/ mypage: /*reading from*/ http://www.rebol.com

    Another line:

    for myvar 1 10 2 [print myvar]


    for /*(set)*/ myvar /*starting from*/ 1 /*reach*/ 10 /*use the stepping*/ 
    2 /* and execute*/ [print myvar]


    Code editors could remove the pairs /* */ and display commenting 
    words in a different color and each line could be read this way:

    set the variable mypage: reading from http://www.rebol.com


    for (set) myvar starting from 1 reach 10 use the stepping 2 and execute 
    [print myvar]


    For people which are learning the language and even for seniors, 
    having this commenting could help a lot.
Geomol
30-May-2013
[2508x2]
I think, you can achieve this with a preprocessor written in REBOL, 
that parse your scripts and remove the comments, before doing the 
script.
Something like:

out: clear ""
script: {

 for /*(set)*/ myvar /*starting from*/ 1 /*reach*/ 10 /*use the stepping*/ 
 2 /* and execute*/ [
		print myvar
	]
}

parse script [some [
	copy s to "/*" (append out s) thru "*/"
	| copy s to end (append out s) 1 skip
]]
do out
GiuseppeC
30-May-2013
[2510]
Geomol, I suppose it is better to have this in the standard language.
Do you think it would be difficult to implement ?
Geomol
30-May-2013
[2511x4]
Not difficult, but is it necessary, and is it rebolish? I haven't 
done a deeper thought about it, but I would guess, it's as easy to 
implement as long strings { ... }.
in the lexer, I mean. After the comment is out, it's done.
But I wouldn't recommend it, as it would make rebol scripts look 
more like the cluster syntax of other languages.
And you could probably find other languages with similar, but other 
syntax, and programmers from those languages would ask for their 
way and on and on. Do it in a preprocessor!
GiuseppeC
30-May-2013
[2515x2]
Geomol, one year ago NickA wrote about a similar feature available 
in LiveCode. Their language is not so flexible as REBOL, if I remember 
correctly only native and not user generated functions have accept 
neutral strings line "at, the, after" to insert in the code.
Isn't a REBOL goal to be more human friendly ?

We all use descriptions and conections words every day. Inserting 
it *for free* inside a line, eeverywhere you want, makes a language 
more readable.
Obviusly "pros" will like not having them but if they think like 
a newbye or even like a semi-pro I suppose they will find the usefullness 
of this imporvemente.
Geomol
30-May-2013
[2517x8]
I think, most will find it harder to read with comments in the middle 
of lines. You can break code over more lines in REBOL, and that way 
add comments in the middle of lines.
do [
	add
	1	; first number
	2	; second number
]
One frind of mine like named arguments to functions in the call of 
the function. You can probably do that in REBOL easily too. Create 
a function, that remove the names of arguments, that is sent in a 
blok together with the values, and then call the real function with 
only the values.
So you could write:

	do-this [add first-value 1 second-value 2]
or something, if that helps.
I like to write as little as possible. :)
Or maybe better than my do-this example, create a dialect, where 
all function calls work with named arguments. The parsing then need 
to look for words, that are functions, find out how many arguments 
they take and remove the argument names. And do it recursively also. 
Should be possible, I think.
Just a crazy thought to consider:

	add (1 ; first arg) (2 ; second arg)
or

	add (1 comment "") (2 comment "")

Doesn't work in REBOL; but you can do that in World.
GiuseppeC
30-May-2013
[2525]
Geomol, I have alway in mind using:

for /*(set)*/ myvar /*starting from*/ 1 /*reach*/ 10 /*use the stepping*/ 
2 /* and execute*/ [print myvar] 
and see it in the editor as:

for (set) myvar starting from 1 reach 10 use the stepping 2 and execute 
[print myvar]
where the "neutral" words are in different colors.
Geomol
30-May-2013
[2526]
I see your point, but it just raises some concerns in relation to 
REBOL. For example, /* is a valid refinement:

>> type? /*
== refinement!


So some might wanna make a shell command in REBOL to be used at the 
REBOL prompt, that reads /* as all the files in the root directory, 
like

	LS /*

That will not be possible, if /* is part of a comment.
Oldes
30-May-2013
[2527]
what about this char: ~

add ~first ~ 1 ~second~ 2
GiuseppeC
30-May-2013
[2528]
Geomol, "/* */" is just an example we can use any combinatio which 
is not so difficult to type :-)
(/* */ It come from AREXX ... oh, memories !)
Geomol
30-May-2013
[2529]
Tilde is an option. There are three function in REBOL using that 
char, the function variations of and, or and xor. I call those and', 
or' and xor' in World, so that's a possibility in R3, if people wants.

And then tilde can be used in URLs, like:

>> type? url://~a
== url!


I can't judge, if that's a problem, if tilde should be used for comments 
too.
Gregg
30-May-2013
[2530]
I don't think REBOL should support it Giuseppe, but you can write 
a dialect that does. Carl mentioned at one point that he considered 
allowing "filler" words, but decided against it. I sometimes allow 
them in my dialects.
GiuseppeC
30-May-2013
[2531x2]
Gregg, in my scenario I propose filler "comments" and not words. 
This should not change REBOL language but only commenting.

The Editor will be in charge for diplaing these comments in different 
colors.

Adding filler words should be a major change in REBOL. I don't wont 
to propose something so big.
Oldes, In my keyboard (italian) there is no tilde key.
The only available characters are
|
 (but I ithink it is already use in REBOL.
and
^

Another proposal would be to have ";" as alternate ending for the 
comment other than CR
In this way we can have 


for ;(set); myvar ;starting from; 1 ;reach; 10 ;use the stepping; 
2 ;and execute; [print myvar] ;standard comment with stops at the 
end of line
Gregg
30-May-2013
[2533]
Filler values of any kind change REBOL. If you really want to do 
that, experiment by using tags as comments, strip all tags after 
loading your code, then DO it. Now see if if really helps people 
when they use your simple dialect. Can the same be acheived, roughly, 
with reformatting and end-of-line comments? 


None of us here can tell you if it is really helpful. It's different, 
but that doesn't mean better. 


Using semicolons as an alternate comment end mark is a HUGE change, 
and not for the better IMO.
Oldes
31-May-2013
[2534]
Yes, the tilda used in urls is a showstopper. Personaly I don't think 
that inline comments are necessary and add some readability. I'm 
fine with current state.
Geomol
31-May-2013
[2535x3]
Just thinking crazy thoughts loud again:

>> comment { ... }
>> ;{ ... }
>>
I know, how and why it works as it does today, but should it be possible 
to:

>> comment { ... } 42
== 42
>> ;{ ... } 42
== 42		; <--- this doesn't happen today.
I can't find a problem in it, but I'm not sure, if I like it.
GiuseppeC
31-May-2013
[2538]
Gregg, Oldes, it is a feature for people who like it.

Having verbose lines really help understand the language but it is 
not for all. I think about it for new user and to say to the world 
"you can write human language resembling lines".

I was sure that professional rebolers would not find this useful... 
but it is not useful for them, for us, it is for another part of 
the world.
Geomol
31-May-2013
[2539x6]
Yes, I understand that. But some things may not be good to get used 
to from the start. Because once you're used to that, would you continue 
using it? Probably you will. So we'll start seeings scripts with 
comments inside lines. Would it be easier or harder to maintain such 
code? Would it be easier or harder for other people to learn from 
such scripts?

I'm not sure.


Maybe I could implement it in a version of World alpha, so we can 
see, how it works in practise.
Even my example in the #World group with comments inside parentheses 
together with arguments are ugly to me. I'm wondering, if it's a 
good thing, that you can do such. :)
On the other hand, in human written languages, we use comments all 
the time (like this extra information here). So (as I said before), 
I'm not sure. :)
Should smileys be allowed in a computer language? :D
>> -D: does [exit]
>> print 42 :-D   
42

I'm rambling!
>> -O: does []
>> :-O
>> -|: does []
>> :-|
>>
Gregg
31-May-2013
[2545]
Giuseppe, all I'm saying is to experiment first. Dialects are great 
for that. I'm not against all verbosity, and was reminded recently 
by an article I read that we can add value by adding information 
and structure to our programs. And I think the idea of the editor 
knowing, and highlighting, filler words is great. At this point, 
and I'm happy to be convinced otherwise, the standard REBOL interpreter 
should not handle it.


Is REBOL more like math or natural language? Would you implement 
comments the same way if you said "Math"?