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

World: r3wp

[Rebol School] Rebol School

PatrickP61
6-Oct-2010
[3333]
so THAT is why I sometimes see some IF statements like that!!!
Maxim
6-Oct-2010
[3334]
yes
GrahamC
6-Oct-2010
[3335]
easier to use the function equivalents
PatrickP61
6-Oct-2010
[3336]
What do you mean GrahamC?
GrahamC
6-Oct-2010
[3337x2]
equal? instead of =
add instead of +
multiply instead of *
PatrickP61
6-Oct-2010
[3339]
ahhh I see
Maxim
6-Oct-2010
[3340x2]
if you want to use ops the way your head probably thinks about logic, 
you'll need to use parens which add a (minuscule) slowdown... really 
its a very small hit.

IF (length? val) > 3 

but this can be recoded as:

IF 3 < length? val
the problem with using funcs is that they extremely confusing to 
read.  so they are very rarely used.
PatrickP61
6-Oct-2010
[3342]
Very good to know!
Maxim
6-Oct-2010
[3343]
and for the record... this was wrong...

length? equal? 3 val

it should be

equal? length? val 3
GrahamC
6-Oct-2010
[3344]
that reads better :)
Maxim
6-Oct-2010
[3345]
the problem is that 3 and equal? go together... obviously I chose 
to order them this way to prove the point... but on any expression 
with more than 2 or 3 ops... function use becomes so complex to decipher 
that its worth it, just adding parens.


I did tests a while back and enclosing things in parens was usually 
practically invisible in loops... just a single path evaluation (like 
pair/x) takes up much more time IIRC.
PatrickP61
24-Oct-2010
[3346]
Got a simple question:


I defined a function called pref.  Its purpose is to simply print 
a precise time and value (which could be one of several values), 
but it is not doing what I expect:

pref:	func [value][print [now/time/precise "-->" value]]

pref	["Your current directory is" what-dir]    ; <-- wanted hh:mm:ss:xxx 
--> Your current directory is ...


but instead I got this:   15:04:43.968 --> Your current directory 
is what-dir


the function did evaluate the now/time/precise correctly, but did 
not evaluate the what-dir.  What can I do to get it to resolve all 
passed variables?
sqlab
24-Oct-2010
[3347]
pref	reduce  ["Your current directory is" what-dir]
PatrickP61
24-Oct-2010
[3348]
oh yes,  reduce!!!  Thank you
PatrickP61
15-Dec-2010
[3349x3]
I don't understand this situation:
>> help same?
USAGE:
        SAME? value1 value2

DESCRIPTION:
        Returns TRUE if the values are identical.
        SAME? is a native value.

ARGUMENTS:
        value1 (any-type!)
        value2 (any-type!)

s1: "series"
s2: copy s1
same? s1 s2
== false


The two values are two separate yet identical values.  Does identical 
mean the same reference ie the same memory location in rebol or am 
I not understanding what identical means?
Should the description read like this:

DESCRIPTION:
        Returns TRUE if the values are identical references.
or 
        Returns TRUE if the values are identical objects.
BrianH
15-Dec-2010
[3352x2]
It returns true if the values in the value slots have exactly the 
same bits. For immediate values (chars, numbers, typesets, ...), 
that is exact equality. For reference values (strings, blocks, objects, 
bitsets, ...) that is exactly the same reference. So that means that 
SAME? 1 1 returns true even though those integers are in different 
value slots.
Since that is two different forms of equality, we had to use the 
more general term "identical". We can't test reference equality on 
immediate values because REBOL is a pass-by-value language, and only 
passes references when that is the value, as it is for reference 
types.
PatrickP61
15-Dec-2010
[3354]
Thank you Brian!  That helps me understand it a little more.
BrianH
15-Dec-2010
[3355x3]
In R3, reference types are the types that aren't in the immediate! 
typeset (which is just documentation):
>> print mold immediate!

make typeset! [none! logic! integer! decimal! percent! money! char! 
pair! tuple!

 time! date! datatype! typeset! word! set-word! get-word! lit-word! 
 refinement!
issue! event!]
That reminds me, I should check whether the immediate! typeset was 
added to R2/Forward and R2 yet.
In R2 it would not have all the same types, of course, but it should 
be a strict subset.
alemar
18-Jan-2011
[3358]
Hi,so i am quite new to the rebol community and have been assigned 
a project to work on.So to be frank i started reading rebol 2 days 
ago and i am quite confused since i worked with c++ before that.I 
am stuck at flow control and operators(sad i know).So basicaly i 
thought of when i moved from delphi to c++,basically if one of you 
guys can provide me with a rebol version of this small program i 
whipped up(flow control number check-the basics) it would be of great 
help to me,so here is my program and thanks in advance.
    

It inputs an integer number n and outputs the sum: 1+22+32+...+n2.I 
use input validation for n to be positive.
#include <iostream>
using namespace std;
    
int main()
{
     int n;
     cin >> n;
     if (n < 0) return 1;
     int sum = 0;
     int i = 0;
     while (i <= n) sum += i*i;
     cout << sum;
     return 0;
}
Sunanda
18-Jan-2011
[3359]
Welcome!
I've posted one possible approach on REBOLforum:

   http://www.rebolforum.com/index.cgi?f=printtopic&topicnumber=46
alemar
18-Jan-2011
[3360x2]
thanks i will have a look at it trough the interpreter this looks 
promissing and not that hard
:D
Maxim
18-Jan-2011
[3362]
REBOL is a very human-oriented language... as little syntax as possible 
(notice how there aren't any parens for functions. for example)
alemar
18-Jan-2011
[3363]
yeah exactly
Maxim
18-Jan-2011
[3364]
if you are very used to C++ this will feel awkard for a while  though 
 :-)   its almost like the total opposite.
alemar
18-Jan-2011
[3365]
well it did look like moon-speak :D
Henrik
18-Jan-2011
[3366]
in a year, C++ will feel awkward :-)
alemar
18-Jan-2011
[3367]
well guys i have to say the community works and i am pleasntly impressed.I 
am checking the libraries now and trying to get the script to work 
since i am getting  ** Access Error: Cannot open /C/users/alemar/download/test.r
** Where: halt-view

** Near: do %/C/users/alemar/download/test.r                     
                                                                 
                   i will figure it out eventually and i can get 
to real programing in this langueage** Access Error: Cannot open 
/C/users/alemar/download/test.r
** Where: halt-view

** Near: do %/C/users/alemar/download/test.r** Access Error: Cannot 
open /C/users/alemar/download/test.r
** Where: halt-view
** Near: do %/C/users/alemar/download/test.r
jocko
18-Jan-2011
[3368]
don't forget to put a header to your file :
Rebol [ ]
Ladislav
18-Jan-2011
[3369]
We don't know whether the file exists, e.g., what does the expression

exists? %/C/users/alemar/download/test.r
Maxim
18-Jan-2011
[3370]
we went over all that in the i'm new group.  :-)
PatrickP61
9-Feb-2011
[3371]
Is there an easy way to suppress a carriage return and line feed 
when hitting the enter button?

For example:  I'd like to be able to do this:
Guess # 1:  XXX <enter> "  Nope, too high, guess lower"
Guess # 2: YYY <enter> "  Nope, too low, guess higher" ...

Can this be done with the ASK somehow?
Henrik
9-Feb-2011
[3372]
http://www.rebol.net/cookbook/recipes/0060.html
PatrickP61
9-Feb-2011
[3373]
Henrik,  That is close, but I'm looking to be able to enter several 
characters, then hit the enter button, but NOT have a LF character 
printed at the time of the enter.
Henrik
9-Feb-2011
[3374x2]
perhaps check the source for the INPUT function
(which is used by ASK)
PatrickP61
9-Feb-2011
[3376]
Will do!!!
BrianH
9-Feb-2011
[3377]
A while ago someone made a text UI dialect for R2 that used ansi 
codes to move around. You might consider looking into that. It is 
likely in the rebol.org script library.
PatrickP61
9-Feb-2011
[3378x3]
I'm stinking close!!!! But not there yet:  Try this in R2:

		set-modes system/ports/input [binary: true]
		string: []
		until [
			prin char: to-char input
			append string char
			char = 13 ; <enter>
			]
		set-modes system/ports/input [binary: false]
		head string
		print "string: " string
After each typed character, I do get the console to print each one 
out, but then I seem to loose the end value when I hit enter
Is there an equivilent for SET-MODES system/ports/input [binary: 
true] in R3?
BrianH
9-Feb-2011
[3381]
No, not yet.
PatrickP61
9-Feb-2011
[3382]
Any ideas on how to get my end value in R2?