World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
alemar 18-Jan-2011 [4055x2] | basically c input |
it inputs a vallue for a varriable | |
Maxim 18-Jan-2011 [4057] | ok. |
alemar 18-Jan-2011 [4058] | this >> is input and << is output |
Maxim 18-Jan-2011 [4059x2] | yeah.. I don't use the C++ console ops a lot, I do C mainly. |
but here goes... n: to-integer ask "enter a number" if n < 0 [quit/return 1] sum: 0 i: 0 while [ i <= n ] [ sum: sum + probe (i * i) i: i + 1] print sum | |
alemar 18-Jan-2011 [4061] | basically when you have cin>>n it awaits a vallue to be inputted in the console window |
Maxim 18-Jan-2011 [4062] | rebol returns 0 by default when you are the end of a script... so no need to add it at the end. |
alemar 18-Jan-2011 [4063x4] | aha |
ok so i just dont understand 2 lines of the code | |
sum:0 | |
i:0 | |
Maxim 18-Jan-2011 [4067] | note, I added a little probe which prints the value at each step. I did this to show you one powerfull aspect of REBOL... you can insert functions like *chains* |
alemar 18-Jan-2011 [4068] | wow |
Maxim 18-Jan-2011 [4069] | the probe actually is transparent and returns the value it received while printing it. |
Pekr 18-Jan-2011 [4070] | alemar, in rebol, the assignment is done via :, not = |
alemar 18-Jan-2011 [4071x2] | aaa like delphi |
i get it | |
Pekr 18-Jan-2011 [4073] | hmm, delphi uses :=, IIRC? But I might be confused by CA Visual OBjects I used in the past :-) |
Maxim 18-Jan-2011 [4074] | just a few functions don't return values (like print) in this case you will get an error, but the error should give you clues |
alemar 18-Jan-2011 [4075x2] | well in delphi you define a value by := and : only explaines the type (boolean,integer.. |
aha gr8 | |
Henrik 18-Jan-2011 [4077] | that's one powerful aspect of REBOL: it figures out the type on its own, mostly. |
alemar 18-Jan-2011 [4078x4] | trying to compile the code now but the compiler from the site is a bit tricky |
** Script error: n has no value ** Where: while ** Near: while [i <= n] [sum: sum + probe (i * i) i: i + 1] | |
:D | |
ok is the Near error a syntax error in the cycle? | |
Maxim 18-Jan-2011 [4082] | the main difference in REBOL is that everything you can manipulate is a value, even functions and objects don't have a special syntax to use... they are values just like anything else. |
Henrik 18-Jan-2011 [4083] | there is no compiler... |
Maxim 18-Jan-2011 [4084] | hehehe... if you paste it directly in the console, the ask will intepret the next line as the answer ;-) |
alemar 18-Jan-2011 [4085] | then what am i using :D |
Pekr 18-Jan-2011 [4086] | :-) |
Maxim 18-Jan-2011 [4087] | so it triggers an error and n is never assigned any value ;-) |
alemar 18-Jan-2011 [4088] | yeah exctly i understood that |
Pekr 18-Jan-2011 [4089] | alemar - rebol is an interpreter ... |
Maxim 18-Jan-2011 [4090] | for the console, just replace the first line by n: 5 |
alemar 18-Jan-2011 [4091x2] | ok so where do you input the code(script)? |
omg i am so wrthless | |
Maxim 18-Jan-2011 [4093] | or you can make a function out of it.... right in the console. |
alemar 18-Jan-2011 [4094x3] | ok so i am not doing this right |
i am wrong at the verry beginning | |
so first things first | |
Henrik 18-Jan-2011 [4097] | the console is for one-line inputs, if you want to type in your code directly. that interactive use of REBOL. the way you want to do this, is create a script in notepad, and run the script from the REBOL console |
alemar 18-Jan-2011 [4098x2] | how do i input the code as a whole in the interpreter |
ahaa | |
Henrik 18-Jan-2011 [4100] | try this: |
alemar 18-Jan-2011 [4101] | does the script have any particular extension? |
Maxim 18-Jan-2011 [4102] | my-func: func [] [ n: to-integer ask "enter a number" if n < 0 [quit/return 1] sum: 0 i: 0 while [ i <= n ] [ sum: sum + probe (i * i) i: i + 1] print sum ] |
Henrik 18-Jan-2011 [4103] | REBOL [] ; right click this text area to copy the text print "hello!" |
Maxim 18-Jan-2011 [4104] | then just: my-func |
older newer | first last |