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

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

Duke
23-Oct-2011
[4513]
BTW, I just C&P the code into the console, and BINGO!!!  :))
Henrik
23-Oct-2011
[4514]
There should be an emacs mode available. I have never used it, though.
Duke
23-Oct-2011
[4515]
@Henrik  What???  Are you ill? LOL ...
Henrik
23-Oct-2011
[4516]
I don't use emacs, hence I don't need the REBOL emacs mode. :-)
Duke
23-Oct-2011
[4517x2]
@Henrik  That's my point !!  :))
Anyway ... thanks you guys!!
Izkata
23-Oct-2011
[4519]
@Duke:  It works in the console if you put the opening bracket of 
the final block on the same line as the closing bracket of the previous 
block, like it is in the example
Duke
24-Oct-2011
[4520]
@Izkata I see that! Thanks. My problem was that CORE's "line continuation" 
symbol - [ - was confusing me. Is there a way to change that to another 
symbol? I was getting it mixed up with the code's own [ and ].
Pekr
24-Oct-2011
[4521]
Have you investigated Core System object? It's interesting. Try: 
"help system" :-) Hmm, I thought it might be there, but it is not:

>> help system/console
SYSTEM/CONSOLE is an object of value:
   history         block!    length: 2
   keys            none!     none
   prompt          string!   ">> "
   result          string!   "== "
   escape          string!   "(escape)"
   busy            string!   "|/-\"
   tab-size        integer!  4
   break           logic!    true
   lookup          function! Console filename completion lookup.
Duke
24-Oct-2011
[4522]
It would have been too good to be true, if it had been there  :D 
How would those values be changed from the console? Like say the 
tab-size?
Pekr
24-Oct-2011
[4523x3]
system/console/tab-size: 8

:-)
it is just normal object, so you can acces its value by path.
So let's say, that we have kind of Windows REBOL registry in here 
:-) A system structure, you can access to get some configuration, 
etc.
Sunanda
24-Oct-2011
[4526]
The one thing you do not seem able to change is the [ continuation 
char
Pekr
24-Oct-2011
[4527x2]
just try e.g. system/console/prompt: "-->"
in fact, we have two continuation chars, [, and {, and both make 
sense - the first one is the continuation of a program, or a block, 
the secong one is for a multiple line string
Duke
24-Oct-2011
[4529]
@Pekr  It might make sense to have 2 line continuation chars, but 
IMHO, it makes no sense to have those chars *the same* as symbols 
you'd find in REBOL code. It can become too confusing -especially 
for beginners. I suppose that is the reason why the console/prompt 
is set to >> and not {{ or ]] :)
Ladislav
24-Oct-2011
[4530x4]
This is a misunderstandin, Duke. #"[" is not a "line continuation" 
symbol
It is simply so, that you can continue, because the interpreter "knows" 
you did not enclose the block yet
use

    do read clipboard://

to input any number of lines
Example:

1
+
2

>> do read clipboard://
== 3
Duke
24-Oct-2011
[4534]
@Ladislav I don't understand what you mean? I might have used the 
wrong terminology - sure! MY corcern is that IF I had a choice, I 
would NOT want to see a { symbol at the beginning of a multi-line 
REBOL snippet, entered at the console. So how does what your advise 
above relate to MY concern?? :)
Sunanda
24-Oct-2011
[4535]
The REBOL console is trying to be helpful in indicating that at least 
one "]" or "}" needs to be supplied to complete an expression.

But I'm with Duke -- more helpful visual indicators would be nice; 
as would the ability to override the default ones.
Duke
24-Oct-2011
[4536]
@Sunanda  I see! So the "[" character is simply a hint. Wouldn't 
it have been more intuitive to have used the "]" char - to indicate 
that an open '"[" needs to be closed?? I'm glad that the LISP REPL 
doesn't do this - not the ones that i use anyway :)) But thanks! 
 You've cleared things up a bit....
Ladislav
24-Oct-2011
[4537x4]
The REBOL console is trying to be helpful in indicating that at least 
one 

]" or "}" needs to be supplied to complete an expression." - yes, 
and that is where I wanted to point out, that there is no "line continuation 
symbol", since what is going on is not that the interpreter encountered 
a "line continuation symbol" (it did not), but that it expect you 
to close the open block
But, OTOH, if you really do want to write an expression like

1
+
2

in the interpreter console, you can use this trick:

do [
1
+
2
]
I would NOT want to see a { symbol at the beginning of a multi-line 
REBOL snippet, entered at the console.
 - that is easy
What exactly it is you *would want* to see?
Duke
24-Oct-2011
[4541]
@Ladislav Thanks for clearing that up!  At the moment, I'm simply 
reading http://www.rebol.com/docs/words/wswitch.htmland trying out 
the snippets to do 2 things:
1. Learn to use the REBOL console
2. Learn REBOL syntax etc


Entering those multiline snippets is what was a problem - until now. 
The console prints a "[" after each CR. For a noob, this chars looks 
and feel just like the ones IN the code. :))
Ladislav
24-Oct-2011
[4542x2]
I do understand, but that does not answer my question. As far as 
I am concerned, I use the

    do read clipboard://

approach when trying some code snippets
But, anyway, what it is you would want to see?
Sunanda
24-Oct-2011
[4544]
here's a cheap'n'cheerful console replacement that concatenates an 
expression until it reads a blank line. Then it executes it. (Two 
blank lines to exit).

Feel free to change the console prompt characters.

my-con: func [
  /local
   in-line
   in-buff
   err
][
forever [
    in-buff: copy ""
    in-line: copy ""
    forever [ 
      in-line: ask "In > "
      if in-line = "" [break]
      append in-buff join " " in-line
      ]
 if in-buff = "" [break]
 err: none
 if error? err: try [print ["Out > " do in-buff] true] [
    print ["Oops > " mold disarm err]
    ]
 ]
 exit
]
Pekr
24-Oct-2011
[4545]
Duke - I think that in fact it is not much of an issue? How often 
do you use multiline expression in REBOL interactive console session? 
It does not allow you to go back anyway, so ...
Duke
24-Oct-2011
[4546x3]
@Sunanda Thanks! Can't wait to try it out! :)
@Ladislav  [quote]do read clipboard://[/quote]


I see! I'm on a Linux Xubuntu box - so I just highlight the text, 
and then right-click paste it into the REBOL console. I get to "see" 
the code, then the results, after a CR. Your method works OK, but 
all I get is the results -- don't seem like "a full meal deal" :)) 
Thanks ...
@Sunanda  Works like a HOT DAMN!!  Thanks! BTW, the command history 
still works after the result is printed - so a person can go back 
and re-do everything, and fix errors.
Duke
25-Oct-2011
[4549]
This code:

val: 123
switch type?/word [
    integer! [print "it's integer"]
    decimal! [print "it's decimal"]
    date! [print "it's a date"]


produces an error msg in v2.7.8 Is it R3 speciffic? It is from the 
R3 docs, but it seemed fairly generic to me.
Sunanda
25-Oct-2011
[4550]
Looks like you are missing:

-- val after type?/word -- so REBOL knows which word's type  you 
are switching on
-- a closing ]
No idea why R3 is happy with that. This works for R2:

val: 123
switch type?/word val [
    integer! [print "it's integer"]
    decimal! [print "it's decimal"]
    date! [print "it's a date"]
   ]
Duke
25-Oct-2011
[4551x2]
Thanks Sunanda! Then there is an error in the docs at http://www.rebol.com/r3/docs/functions/switch.html.
Who do I alert?
I just did a "Help type? at the console, and got:

TYPE? value /word


Does this output not seem counter-intuitive to you guys? Especially 
when the syntax is:

TYPE?/word/ value   ; I used the / char to indicate an option


This tells me that the type? word is followed by an optional refinement, 
but always needs a "value" - in that order. The console help output 
seems to have it reversed. What do you think?
Endo
25-Oct-2011
[4553]
All the refinements are optional, it's a bit confusing for a beginner 
but otherwise it will be more confusing. Try:  help find

There are lots of refinement. HELP shows the normal usage and then 
the optional refinements and their arguments.
Ladislav
25-Oct-2011
[4554]
Hmm, looks that I forgot (once again) how to log in to the R3 docs.
Henrik
25-Oct-2011
[4555]
Duke, refinements can have arguments as well, so the order as shown 
in the help is exactly the same as when you define a function header.
Duke
25-Oct-2011
[4556]
@Henrik So in the case of the word TYPE?, is "value" an argument 
of the refinement, or of the word itself? Because it seems to be 
used as if it was an argument of the /word refinement.
Henrik
25-Oct-2011
[4557x4]
The format is name, followed by arguments to that name. So VALUE 
is an argument to TYPE and the /WORD refinement has no arguments.
Refinements are options, sometimes used in twos or threes, and the 
disadvantage here is that the argument list then can become hard 
to read. It's a good skill to create functions without too many refinements. 
I personally consider refinements to be one of the less stellar parts 
of REBOL.
If you type:

source type?


you will see the function header as it is stated for the function. 
It comes in the same order as in the help documentation.
So, why isn't it just the other way around, like in the help? You 
could in principle do that. It just gives you many more arguments 
that you would be forced to type.

TYPE? could look like this:

type? 5 word

So, if you didn't want the refinement, you would have to type:

type? 5 none


For functions with many arguments, you would have to type something 
like:

my-function 1 none none none none none none

which is no fun to type directly.
Duke
25-Oct-2011
[4561]
@Henrik But Sunanda responded above to my original question by indicating 
that the syntax was:

switch type?/word val [


So val is an argument to TYPE?, but it's written after the refinement?? 
That is NOT intuitive to me!!
Henrik
25-Oct-2011
[4562]
A refinement is latched onto a function, so that you know that the 
refinement is part of that function. Hence, you must type out the 
function name, followed directly by the refinement without spacing. 
Then you type the function arguments and after that, the refinement 
arguments.