Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Using a Math oper. buried in a variable

 [1/47] from: mumpsoid:gmx at: 2-Apr-2009 12:15


Hey... I want to do something like: num1: = 6 num2: = 5 op: "*" print [num1 op num2] and get 30 as the result. How in the %^-#*& do you do this in REBOL? Not yet REBOLized in Alberta ;) -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [2/47] from: tom:conlin:gm:ail at: 2-Apr-2009 11:21


Duke Normandin wrote:
> Hey... > I want to do something like:
<<quoted lines omitted: 4>>
> and get 30 as the result. How in the %^-#*& do you do this in REBOL? > Not yet REBOLized in Alberta ;)
op: '* ... print reduce ...

 [3/47] from: gregg:pointillistic at: 2-Apr-2009 12:46


Hi Duke, DN> I want to do something like: DN> num1: = 6 DN> num2: = 5 DN> op: "*" DN> print [num1 op num2] DN> and get 30 as the result. How in the %^-#*& do you do this in REBOL? I addition to Tom's answer, this may help explain word usage: http://www.rebol.com/docs/core23/rebolcore-4.html#section-5.2 As with most things in REBOL, there are a number of ways to do what you want. Here's another one:
>> num1: 6
== 6
>> num2: 5
== 5
>> op: :* >> op num1 num2
== 30
>> print [op num1 num2]
30 -- Gregg

 [4/47] from: Scott:Wall:xwave at: 2-Apr-2009 15:53


Hi Duke,
> As with most things in REBOL, there are a number of ways to do what > you want. Here's another one:
<<quoted lines omitted: 7>>
>>> print [op num1 num2] >30
Still another way is to leave op: "*" and use: do reform [num1 op num2] Scott

 [5/47] from: izkata::gmail at: 2-Apr-2009 14:46


On Thu, Apr 2, 2009 at 1:46 PM, Gregg Irwin <gregg-pointillistic.com> wrote:
> Hi Duke, > DN> I want to do something like:
<<quoted lines omitted: 16>>
>>> print [op num1 num2] > 30
Extra explanation for this one. There's an issue in how the interpreter sees op! values (anything with infix notation), so the infix use of the op is lost here. That's why it's prefix notation inside the print block. -- =E5=A5=8F=E3=81=A7=E3=81=A6=E5=A4=A2

 [6/47] from: mumpsoid:gmx at: 2-Apr-2009 14:26


On Thu, 2 Apr 2009, Gregg Irwin wrote:
> Hi Duke, > DN> I want to do something like:
<<quoted lines omitted: 18>>
> -- Gregg >> num1
== 5
>> num2
== 6
>> op num1 num2
== 6
>> print [op num1 num2]
* 5 6
>>
????? -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [7/47] from: mumpsoid:gmx at: 2-Apr-2009 14:30


On Thu, 2 Apr 2009, tomc wrote:
> Duke Normandin wrote: > > Hey...
<<quoted lines omitted: 14>>
>> >> op: '*
== *
>> num1
== 5
>> num2
== 6
>> print [num1 op num2]
5 * 6
>>
??? -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [8/47] from: mumpsoid:gmx at: 2-Apr-2009 14:33


On Thu, 2 Apr 2009, Izkata wrote:
> On Thu, Apr 2, 2009 at 1:46 PM, Gregg Irwin <gregg-pointillistic.com> wrote > :
<<quoted lines omitted: 31>>
>> >> num1
== 5
>> num2
== 6
>> op
== *
>> print [op num1 num2]
* 5 6
>>
I can't win today..... Must be something wrong with my interpreter. -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [9/47] from: henrikmk::gmail at: 2-Apr-2009 22:36


>>> num1 > == 5
<<quoted lines omitted: 6>>
>>> > I can't win today..... Must be something wrong with my interpreter.
Forgetting to REDUCE:
>> print reduce [op num1 num2]
== 30 -- Regards, Henrik Mikael Kristensen

 [10/47] from: mumpsoid:gmx at: 2-Apr-2009 14:37


On Thu, 2 Apr 2009, Wall, Scott wrote:
> Hi Duke, > > As with most things in REBOL, there are a number of ways to do what
<<quoted lines omitted: 13>>
> do reform [num1 op num2] > Scott
JOY!!!!!!!!
>> >> num1
== 5
>> num2
== 6
>> op
== *
>> do reform [num1 op num2]
== 30
>>
Is it OK for me to think that this is a PITA? -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [11/47] from: mumpsoid:gmx at: 2-Apr-2009 14:41


On Thu, 2 Apr 2009, Henrik Mikael Kristensen wrote:
> >>> num1 > > == 5
<<quoted lines omitted: 10>>
> >> print reduce [op num1 num2] > == 30
MORE JOY!!!!!!
>> print reduce [op num1 num2]
30
>>
None of this is intuitive though, is it? Anyway, thanks for the solution. -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [12/47] from: henrikmk:gm:ail at: 2-Apr-2009 22:42


On Thu, Apr 2, 2009 at 10:37 PM, <mumpsoid-gmx.com> wrote:
> On Thu, 2 Apr 2009, Wall, Scott wrote: >>
<<quoted lines omitted: 32>>
>>> > Is it OK for me to think that this is a PITA?
Actually, it's only one form: Code is data and data is code, but the method above creates a string, which is fast in REBOL2 due to the string being in ASCII format, but slower in R3, because it's converted to unicode and away from unicode. I believe the most correct and fastest method here is to assign the function directly to 'op, so you don't have to put things inside a block. It was mentioned earlier:
>> op: :* >> op num1 num2
== 30 -- Regards, Henrik Mikael Kristensen

 [13/47] from: gregg:pointillistic at: 2-Apr-2009 14:44


HMK> Forgetting to REDUCE:
>>> print reduce [op num1 num2]
HMK> == 30 Hmmm, what REBOL version and OS are you on Duke? The reduce should not be required. My post was copied from a live console. Is it required on OS X Henrik? -- Gregg

 [14/47] from: mumpsoid:gmx at: 2-Apr-2009 14:47

Thanks Everybody for Math Oper solution


Hey... You guys Rock! I'll keep plugging away at REBOL. Maybe I've done too much Perl, though. -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [15/47] from: henrikmk:gm:ail at: 2-Apr-2009 22:48

Re: Using a Math oper. buried in a variable


On Thu, Apr 2, 2009 at 10:44 PM, Gregg Irwin <gregg-pointillistic.com> wrote:
> > HMK> Forgetting to REDUCE: > >>>> print reduce [op num1 num2] > HMK> == 30 > > Hmmm, what REBOL version and OS are you on Duke? The reduce should not > be required. My post was copied from a live console. Is it required on > OS X Henrik?
Before you close your console, what is your value of 'op? If it's a word, then print will not evaluate without reduce. If it is a function, then it will evaluate without reduce. I know there was an example earlier where 'op would be a function, and so it shouldn't be mixed up. -- Regards, Henrik Mikael Kristensen

 [16/47] from: tom:conlin:gma:il at: 2-Apr-2009 13:50


it is because you have not stretched your mind mastering top posting ;^)

 [17/47] from: gregg:pointillistic at: 2-Apr-2009 14:50


Hi Duke,
>>> num1
mgc> == 5
>>> num2
mgc> == 6
>>> op
mgc> == *
>>> do reform [num1 op num2]
mgc> == 30
>>>
mgc> Is it OK for me to think that this is a PITA? Sure, you can think whatever you want. :) How would you like it to work, and what is your ultimate goal? A big part of understanding REBOL is figuring out when evaluation occurs, and how values are evaluated. I almost never DO strings. 1) it's just non-REBOLish. REBOL is a data language, and you can almost always build up expressions to evaluate far easier using native types, and 2) it's a risky habit to get into, in case, one day, you write something that uses untrusted data. -- Gregg

 [18/47] from: mumpsoid:gmx at: 2-Apr-2009 14:52


On Thu, 2 Apr 2009, Henrik Mikael Kristensen wrote:
> On Thu, Apr 2, 2009 at 10:37 PM, <mumpsoid-gmx.com> wrote: > >
<<quoted lines omitted: 48>>
> == 30 >> about
REBOL/Core 2.7.6.2.5 17-Mar-2008 Copyright 2000-2008 REBOL Technologies. All rights reserved. REBOL is a trademark of REBOL Technologies. WWW.REBOL.COM
>> op: :* >> op num1 num2
== 30
>>
Cool! but I would have never fingered that out in a million years. :) -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [19/47] from: mumpsoid:gmx at: 2-Apr-2009 14:55


On Thu, 2 Apr 2009, tomc wrote:
> it is because you have not stretched your mind mastering top posting ;^) > > None of this is intuitive though, is it? Anyway, thanks for the > > solution. > >
I'm sure you meant to say mind-shattering! :)) -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [20/47] from: henrikmk:gmai:l at: 2-Apr-2009 22:58


>>> op: :* >>> op num1 num2 > == 30 >>> > > Cool! > > but I would have never fingered that out in a million years. :)
Alright, a little theory: :* is a get-word! and when you get-word something, you get its content. In this case, you are getting a function body, but not evaluating it. This way, you can set words to a particular function body, so above, 'op is set to that function body. It's similar to saying: get '* Whereas evaluating it, would be equivalent to: do '* Try something like: probe :for and out pours the sourcecode for the FOR function. -- Regards, Henrik Mikael Kristensen

 [21/47] from: mumpsoid:gmx at: 2-Apr-2009 15:09


On Thu, 2 Apr 2009, Gregg Irwin wrote:
> Hi Duke, > >>> num1
<<quoted lines omitted: 11>>
> A big part of understanding REBOL is figuring out when evaluation > occurs, and how values are evaluated.
I can see that...
> I almost never DO strings. 1) it's just non-REBOLish. REBOL is a data > language, and you can almost always build up expressions to evaluate > far easier using native types, and 2) it's a risky habit to get into, > in case, one day, you write something that uses untrusted data.
I agree!
>> about
REBOL/Core 2.7.6.2.5 17-Mar-2008 Copyright 2000-2008 REBOL Technologies. All rights reserved. REBOL is a trademark of REBOL Technologies. WWW.REBOL.COM
>> op: :* >> op num1 num2
== 30
>> integer? num1
== true
>> integer? num2
== true
>>
I don't believe that this was issue here. However, it wa an issue in my little "learning" program: REBOL [ title: "Calculator Program" author: "Duke Normandin" date: 30-March-2009 File: %myCalc.r version: 1.0.0 ] clrscrn: does [print "^(1B)[2J"] until [ clrscrn num1: ask "Enter the 1st number: " num2: ask "Enter the 2nd number: " op: ask "Enter an operator [+ - * /]: " any [ if op = "+" [ print ["The answer is: " ((to-integer num1) + (to-integer num2))] ] if op = "-" [ print ["The answer is: " ((to-integer num1) - (to-integer num2))] ] if op = "*" [ print ["The answer is: " ((to-integer num1) * (to-integer num2))] ] if op = "/" [ print ["The answer is: " ((to-integer num1) / (to-integer num2))] ] print ["You entered an invalid operator"] ] confirm "Are you done? Y/N: " ] -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [22/47] from: gregg:pointillistic at: 2-Apr-2009 17:38


mgc> but I would have never fingered that out in a million years. :) That's why I posted this link: http://www.rebol.com/docs/core23/rebolcore-4.html#section-5.2 Don't worry though, once you get a handle on the basics, you'll find some *really* great "features". :) -- Gregg

 [23/47] from: mumpsoid:gmx at: 2-Apr-2009 18:21


On Thu, 2 Apr 2009, Gregg Irwin wrote:
> mgc> but I would have never fingered that out in a million years. :) > > That's why I posted this link: > > http://www.rebol.com/docs/core23/rebolcore-4.html#section-5.2
Thanks! In the past week I must have read that page about 10 times. It better start sinking in quick ;)
> Don't worry though, once you get a handle on the basics, you'll find > some *really* great "features". :) > > -- Gregg
I'm sure you're right! I'll just hang in there for awhile... Otherwise thanks for the invite over to REBOL3 World. -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [24/47] from: mumpsoid::gmx::com at: 2-Apr-2009 18:24


On Thu, 2 Apr 2009, Henrik Mikael Kristensen wrote:
> >>> op: :* > >>> op num1 num2
<<quoted lines omitted: 16>>
> probe :for > and out pours the sourcecode for the FOR function.
Thanks for the extra theory. I'm slowly morphing into a REBOLer. -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [25/47] from: Scott::Wall::xwave::com at: 3-Apr-2009 9:58


Gregg wrote:
> As with most things in REBOL, there are a number of ways to do what > you want. Here's another one:
...
>>> op: :*
I'm now trying to use this form in my program. But I'm having trouble when it comes to dividing. Here is what I tried doing and how it failed:
>> op: :/
** Syntax Error: Invalid word-get -- : ** Near: (line 1) op: :/ Any ideas on how to get this to work? Scott.

 [26/47] from: semseddinm:bircom at: 3-Apr-2009 16:48


> -----Original Message----- > From: rebol-bounce-rebol.com [mailto:rebol-bounce-rebol.com] On Behalf
<<quoted lines omitted: 18>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
You can try this one: p: :divide and also you can try "trace on" to see what happens. Sems

 [27/47] from: henrikmk:gm:ail at: 3-Apr-2009 15:49


On Fri, Apr 3, 2009 at 2:58 PM, Wall, Scott <Scott.Wall-xwave.com> wrote:
> Gregg wrote: >> As with most things in REBOL, there are a number of ways to do what
<<quoted lines omitted: 7>>
> ** Near: (line 1) op: :/ > Any ideas on how to get this to work?
It will not work, since / can't be directly converted to a word and used as a get-word. The trick would be to write it first as a string and convert it: get to-get-word "/" That is not very pretty, is it? (But keep it in mind, when you need to convert something unwieldy to a word. :-)) So we can do something else: + - * and / are normally infix operators (2 + 3). In REBOL 2 you can use them as prefix operators (+ 2 3), which would work in the examples, but you can't do this in REBOL 3. Instead, use the named functions ADD, SUBTRACT, MULTIPLY and DIVIDE, so: op: :divide should work for you. -- Regards, Henrik Mikael Kristensen

 [28/47] from: mumpsoid:gmx at: 3-Apr-2009 9:02

let's re-visit math oper. in a var.


Hey.... REBOL [ title: "Calculator Program" author: "Duke Normandin" date: 30-March-2009 File: %myCalc.r version: 1.0.0 ] clrscrn: does [print "^(1B)[2J"] until [ clrscrn num1: ask "Enter the 1st number: " num2: ask "Enter the 2nd number: " op: ask "Enter an operator [+ - * /]: " op2: join ":" :op print reform ["result 1: " (to-integer num1) op (to-integer num2)] ;NO JOY.... print reduce ["result 2: " op num1 num2] ; NO JOY...... print ["result 3: " op2 num1 num2] ; NO JOY...... confirm "Are you done? Y/N: " ] What's wrong _now_........? -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [29/47] from: Scott:Wall:xwave at: 3-Apr-2009 12:12


Hi Duke,
> op: ask "Enter an operator [+ - * /]: " > op2: join ":" :op
...
> What's wrong _now_........?
You could try using what Henrik suggested: op: get to-get-word ask "enter operand" Then
>> op num1 num2
would perform the requested operation on the two numbers. Scott.

 [30/47] from: Scott:Wall:xwave at: 3-Apr-2009 12:16

Re: Using a Math oper. buried in a variable


Henrik wrote:
> It will not work, since / can't be directly converted to a word and > used as a get-word. The trick would be to write it first as a string > and convert it: > get to-get-word "/" > That is not very pretty, is it? (But keep it in mind, when you need to > convert something unwieldy to a word. :-))
It may not be pretty but I like it. I'm starting with a string anyway so this looks like a nice generic approach.
> So we can do something else: ...
Nah, I like the first solution better. Thanks, Scott.

 [31/47] from: mumpsoid:gmx at: 3-Apr-2009 9:21

Re: let's re-visit math oper. in a var.


On Fri, 3 Apr 2009, Wall, Scott wrote:
> Hi Duke, > > op: ask "Enter an operator [+ - * /]: "
<<quoted lines omitted: 7>>
> would perform the requested operation on the two numbers. > Scott.
Hey Scott... No joy.... Thanks for your input! as well as everybody on the list. I think that I'm going to leave REBOL alone for awhile, until I cool off. have a good one.... -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [32/47] from: gregg:pointillistic at: 3-Apr-2009 10:02


Hi Duke, DN> What's wrong _now_........? Remember, REBOL doesn't evaluate strings they way you might think it does. You can DO a string, and you should play with that, but they are not implicitly evaluated. So, when you do this: DN> op: ask "Enter an operator [+ - * /]: " DN> op2: join ":" :op The resulting op is just a string with a colon on the front. Enter an operator [+ - * /]: + == ":+" If you DO the resulting string (":+"), REBOL will, indeed, convert it to an op, but you're not doing that in your code, you're code is doing this: print reform ["result 1: " (to-integer num1) ":+" (to-integer num2)] Note here that there is an important distinction between DO and REDUCE.
>> s: ":+"
== ":+"
>> reduce s
== ":+"
>> do s >> type? do s
== op! When working with REBOL, if things aren't working as expected, it's a good idea to check the type of value you're operating on, and to MOLD them when printing them for analysis.
>> print "+"
+
>> print '+
+
>> print #+
+
>> print mold "+"
+
>> print mold '+
+
>> print mold #+
#+ clrscrn: does [print "^(1B)[2J"] until [ clrscrn num1: ask "Enter the 1st number: " while [error? try [num1: to-integer num1]] [ print ["Sorry," mold num1 "doesn't look like a number to me"] num1: ask "Enter the 1st number: " ] num2: ask "Enter the 2nd number: " while [error? try [num2: to-integer num2]] [ print ["Sorry," mold num2 "doesn't look like a number to me"] num2: ask "Enter the 2nd number: " ] op: ask "Enter an operator [+ - * /]: " while [not find "+-*/" trim op] [ print ["Sorry," mold op "doesn't look like one of the operators I know"] op: ask "Enter an operator [+ - * /]: " ] ;op: get to word! op ; try this, to see why it doesn't work op: get select ["+" add "-" subtract "*" multiply "/" divide] op print reduce ["result 1: " op num1 num2] confirm "Are you done? Y/N: " ] -- Gregg

 [33/47] from: tim-johnsons:web at: 3-Apr-2009 12:04


On Friday 03 April 2009, mumpsoid-gmx.com wrote:
> Thanks for your input! as well as everybody on the list. > I think that I'm going to leave REBOL alone for awhile, until > I cool off. have a good one....
When I started to learn rebol, I had been working for 11 years almost exclusively with C/C++ and a little assembler coding. I was told more than once - on this list - to stop "thinking in C". It was good advice. I was more fortunate than you in that I started with a simpler topic: loop iteration and FTP - and FTP in rebol is ridiculously simple. You have actually begun with the most difficult (and powerful) feature of rebol - symbolic evaluation. I've noted that the rebol community doesn't often refer to rebol as having "symbolic programming" features - such as lisp,, but I would bet that someone coming from lisp would make that note. When you get back to rebol - and I hope that will be soon - you might find that conceptual seeds have been planted and that they might now be sprouting. Good luck tim

 [34/47] from: mumpsoid:gmx at: 3-Apr-2009 14:28


On Fri, 3 Apr 2009, Tim Johnson wrote:
> On Friday 03 April 2009, mumpsoid-gmx.com wrote: > > Thanks for your input! as well as everybody on the list.
<<quoted lines omitted: 8>>
> the most difficult (and powerful) feature of rebol - symbolic > evaluation.
Leave it to me to always be taking the long, hard road to wherever ;) Must be my former U.S.M.C. experience jinxing me ;)) Anyway, I'm also studying (and liking) an old "database" language called Mumps or "M" - heavily used in the Healthcare and financial circles. That little "calculator routine" that I was using as a sandbox took me 10 minutes to write properly in Mumps, including error trapping. Just another tool in my toolbelt...
> I've noted that the rebol community doesn't often refer to > rebol as having "symbolic programming" features - such as > lisp,, but I would bet that someone coming from lisp would > make that note.
I'm also having a serious look at "newLisp". I'll be trying out my little calculator program in it as well.
> When you get back to rebol - and I hope that will be soon - you > might find that conceptual seeds have been planted and that > they might now be sprouting. > > Good luck > tim >
Thank for the encouragement and kind words - and you as well!! -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [35/47] from: gregg:pointillistic at: 3-Apr-2009 14:54


Hi Duke, mgc> Anyway, I'm also studying (and liking) an old "database" language mgc> called Mumps or "M" - heavily used in the Healthcare and financial mgc> circles. That little "calculator routine" that I was using as a mgc> "sandbox" took me 10 minutes to write properly in Mumps, including mgc> error trapping. Just another tool in my toolbelt... What does the result look like in M (is it Cache' or something else you're using)? Earlier I asked about what you expected it to work like, because that's one of the things that trips people up when they come to REBOL from other languages. In other languages that support an eval concept, there is code, and you can build up strings and call "eval" on them, interpreting them as code. The equivalent in REBOL is DO, but there is much more flexibility in REBOL. DOing strings is rare. You are much better off building up blocks. The hard part here, with your example, is that user input is going to start out as strings and you need to convert it to REBOL types. And what you might normally do in REBOL, for a problem like this, is build up the input and use PARSE, but I don't usually throw that at newcomers as an answer, because it's "overload time" if you're just getting started with REBOL. I think the biggest <click> in my head was when I finally understood that there is no code in REBOL, there is only data that is evaluated. -- Gregg

 [36/47] from: tim-johnsons:web at: 3-Apr-2009 15:17


On Friday 03 April 2009, Gregg Irwin wrote:

 [37/47] from: compkarori:gmai:l at: 4-Apr-2009 4:57


If you wanted to write a single line calculator I would let the user input an entire arithmetic expression. Then parse it to make sure it was syntactically correct ( using the example from the parse documentation pages ) And then 'do it. This is what I did when I added a line calculator to my applet that does prescribing .. to allow the users to calculate doses. On Sat, Apr 4, 2009 at 12:17 PM, Tim Johnson <tim-johnsons-web.com> wrote:
> On Friday 03 April 2009, Gregg Irwin wrote: >> I think the biggest <click> in my head was when I finally understood
<<quoted lines omitted: 3>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu http://www.synapsedirect.com Synapse - the use from anywhere EMR.

 [38/47] from: petr:krenzelok:seznam:cz at: 4-Apr-2009 8:09


Graham Chiu napsal(a):
> If you wanted to write a single line calculator I would let the user > input an entire arithmetic expression. > Then parse it to make sure it was syntactically correct ( using the > example from the parse documentation pages ) > And then 'do it. >
Here's R2 desktop Demo section Calculator script. Pretty tiny, and does the job: http://www.rebol.com/view/demos/calculator.r -pekr-

 [39/47] from: anton:wilddsl:au at: 4-Apr-2009 17:25


Just before you go, try this: Paste it into your console or put it in a script. print "Press escape to exit the loop." forever [ num1: to-integer ask "Enter the 1st number: " num2: to-integer ask "Enter the 2nd number: " op: all [pos: find "+-*/" ask "Enter an operator [+ - * /]: " get to-word form first pos] result: op num1 num2 print ["result:" result] ] Note that TO-INTEGER needs valid input, or errors to be trapped, but we can add that later. OP is here guaranteed to be one of the four operators or NONE (thanks to ALL). Regards, Anton. mumpsoid-gmx.com wrote:

 [40/47] from: mumpsoid:gmx at: 4-Apr-2009 7:55


On Sat, 4 Apr 2009, Anton Rolls wrote:
> Just before you go, try this: > Paste it into your console or put it in a script.
<<quoted lines omitted: 17>>
> > I think that I'm going to leave REBOL alone for awhile, until > > I cool off. have a good one....
I see that I wa using the "to-integer' function in the wrong place... Your "op:" assignment line is of course the key (kudos to you) and I suspect contains a lot of "keys" to understanding REBOL. Nice little script! Thanks for the extra mile.... BTW, it works exactly as to what I had in mind. I don't _need_ this calculator for anything -- it's merely a learning project. Thanks again. -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [41/47] from: mumpsoid:gmx at: 4-Apr-2009 8:06


On Fri, 3 Apr 2009, Gregg Irwin wrote:
> Hi Duke, > mgc> Anyway, I'm also studying (and liking) an old "database" language
<<quoted lines omitted: 6>>
> like, because that's one of the things that trips people up when they > come to REBOL from other languages.
I'm using an OpenSource MSM clone called MV1 by Ray Newman. The results in M(umps) are exactly like that from Anton's script. The code is about as short as well. [snip]
> I think the biggest <click> in my head was when I finally understood > that there is no code in REBOL, there is only data that is evaluated. > > -- Gregg
It's ALL data - just manipulate the data! It's ALL data - just manipulate the data! It's ALL data - just manipulate the data! It's ALL data - just manipulate the data! Say that a 1000 times - out load - Duke. ;)) Thanks! -- Duke Normandin A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?

 [42/47] from: Scott:Wall:xwave at: 6-Apr-2009 12:59

Re: Using a Math oper. buried in a variable


Henrik wrote:
> It will not work, since / can't be directly converted to a word and > used as a get-word. The trick would be to write it first as a string > and convert it: > get to-get-word "/" > That is not very pretty, is it? (But keep it in mind, when you need to > convert something unwieldy to a word. :-))
Unfortunately, this approach doesn't seem to work on the "^^" operator.
>> op: get to-get-word "^^"
** Script Error: ^ has no value ** Near: op: get to-get-word "^^" I can however use :power. Shouldn't there be a consistent way to convert all operators from string to get-word? I am also trying to inject parentheses without much success. Is this even possible? I've tried: x: '( x: get to-get-word "(" x: :( Each attempt failed. Thanks, Scott.

 [43/47] from: anton:wilddsl:au at: 7-Apr-2009 3:46


Hi Scott, These apparent inconsistencies are not as inconsistent as they might seem. First, with "^^", you found the escape character. In any symbol set you will find "inconsistencies" around the escape character. What the above string represents is a single character ^. It just appears in code that there are two. The string you need to type can be found by doing this: to-string first [^^] but actually, now we remember that ^^ isn't the Rebol power operator anyway! It's **. Oh well. :-) Second, you can't inject parenthesis as if they're words, because they're not words. They are Rebol syntax at a more fundamental level than words. (I think that's a correct way to explain it, anyway.) If you want to create parens, then do it like this: append copy () something or to-paren reduce [some stuff] It's just the same with blocks and strings. They are all series! delimiters. " [ ] ( ) You can make the delimiters into words, but then how are you going to use them? Regards, Anton. Wall, Scott wrote:

 [44/47] from: carl:cybercraft at: 7-Apr-2009 7:09


On Monday, 6-April-2009 at 12:59:55 Wall, Scott wrote,
>I am also trying to inject parentheses without much success. Is this >even possible? I've tried:
<<quoted lines omitted: 3>>
>Each attempt failed. >> x: :-(
** Syntax Error: Missing ) at end-of-script ** Near: (line 1) x: :-(

 [45/47] from: Scott:Wall:xwave at: 7-Apr-2009 10:33


Hi Anton,
> but actually, now we remember that ^^ isn't the Rebol > power operator anyway! It's **. Oh well. :-)
Whoops. You're right. The ** operator seems to work well. My input string used ^, so I foolishly assumed that Rebol did as well. </blush>
> If you want to create parens, then do it like this: > > append copy () something
Couldn't get this append to work.
> or > > to-paren reduce [some stuff]
This, however, works like a charm. Thanks, Scott

 [46/47] from: sqlab:gmx at: 7-Apr-2009 15:58


The example of Anton works unfortunately not in the console, as the console evaluates the paren and () is equivalent to a do, so you get .. nothing
>> (1)
== 1
>> >> () >> >> type? ()
== unset!
>>
You can overcome of this in the console by shielding it in a block
>> first [()]
== ()
>> type? first [()]
== paren!
>>
And then you get the desired behavior in the console too
>> append first [()] 1
== (1)
>>
Wall, Scott wrote:

 [47/47] from: anton:wilddsl:au at: 8-Apr-2009 4:37


sqlab wrote:
> The example of Anton works unfortunately not in the console, > as the console evaluates the paren and () is equivalent to a do, so you > get .. nothing
It doesn't work in a script either. Sorry I only created an almost-working example :-) But you *can* use TO-PAREN: append to-paren [] 'something as Scott found out, or LOAD: append load "()" 'something which might be more visually appealing. Regards, Anton.

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted