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

[REBOL] Re: Using a Math oper. buried in a variable

From: mumpsoid:gmx at: 2-Apr-2009 15:09

On Thu, 2 Apr 2009, Gregg Irwin wrote:
> 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 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?