• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

Steeve
21-Apr-2012
[54]
How have you discovered  Rebol, If I may ask ?
Sujoy
21-Apr-2012
[55x4]
online! was looking for something light and fast (in dev terms)
rebol is ideal
if i do:

fact1: 'a
o: make object [a: "100.9"]
append objs o
foreach obj objs [if equal?  do bind blk 'obj true [print obj/a]]
** Script Error: Invalid argument: a: "100.0"
wtf!
Steeve
21-Apr-2012
[59]
typo again
>> o: make object! [a: "100.9"]
you need sleeping time
Sujoy
21-Apr-2012
[60]
nope. i corrected that and still the same error.


i have data stored in json. i use json.r to convert to rebol objects. 
i want to create a query layer on top of this - which is why the 
expression builder...
the fact1 is an attr of the data object. these can be nested.
how best can i build the expression to retrieve the value i want?
Steeve
21-Apr-2012
[61]
There's no better response than: it can be done.
You just have to correct the bugs as they come.
Sujoy
21-Apr-2012
[62]
:)
Steeve
21-Apr-2012
[63]
is the complete error that one ?

** Script Error: Invalid argument: a: "100.0"

** Where: to-decimal
** Near: to decimal! :value
Sujoy
21-Apr-2012
[64]
yes
Steeve
21-Apr-2012
[65x2]
so you are trying to convert to a decimal something not convertible
add a probe, just after to-decimal
Sujoy
21-Apr-2012
[67]
hmmm...not that i know of...just using the test data i put in here:

>> probe objs
[make object! [
        a: make object! [
            a: "100.0"
        ]
    ] make object! [
        a: make object! [
            a: "99.0"
        ]
    ] make object! [
        a: "199.0"
    ]]
Steeve
21-Apr-2012
[68]
you are trying to convert an object to a decimal
Sujoy
21-Apr-2012
[69]
as long as fact1: 'a/a it works fine.
if fact1: 'a - boom!
Steeve
21-Apr-2012
[70]
because your objects have structures which are not always the same
Sujoy
21-Apr-2012
[71]
how do i tackle this?
Steeve
21-Apr-2012
[72]
what is the name of the decimal attribute ?
Sujoy
21-Apr-2012
[73]
a


blk: any [greater? to-decimal probe do bind reduce [fact1] obj num1 
| greater? to-decimal do bind obj/:fact1 obj num1]??
Steeve
21-Apr-2012
[74]
Currenlty 'a stands for either an object or a string, you can't be 
that vague.
You must choose a clear name  to identify the decimal attribute
Sujoy
21-Apr-2012
[75]
rats!
Steeve
21-Apr-2012
[76x3]
or you must check in your code when 'a is an object!
and fact1 must be initialized accodingly.
Either with 'a either with 'a/a
question:
an object 'a always has only one property called 'a ?
Sujoy
21-Apr-2012
[79]
yes
Steeve
21-Apr-2012
[80x3]
ok it's simpler then, let me try...
fact1: 'a
get-prop: func [o][either object? o [first next second o][o]]

blk: [greater? to-decimal get-prop do bind reduce [fact1] obj num1]objs: 
[]
another question. 

Why are you using the blk variable instead of coding directly in 
the foreach loop ?
The code would be simpler.
Sujoy
21-Apr-2012
[83]
meaning?
Steeve
21-Apr-2012
[84x5]
This is the same thing without the need of the blk code:

foreach obj objs [
	if num1 < get-prop obj/:fact1 [print obj/a]]
]
much simpler, no need to rebind anything
small mistake, missed the to-decimal.

foreach obj objs [
	if num1 < get-prop to-decimal obj/:fact1 [print obj/a]]
]
arghhh

foreach obj objs [
	if num1 < to-decimal get-prop obj/:fact1 [print obj/a]]
]
Anyway, you see the idea
Sujoy
21-Apr-2012
[89x2]
yes...
much simpler
caelum
22-Apr-2012
[91]
Is it possible to change the background color of the view led? Or 
are the only states available 'true' and 'false' which are green 
and red? I want different background colors for 'true' and 'false' 
states.

view center-face layout [
	across
	l1: led
	label "State" state: field

	btn "Change led state" [
		either l1/data [
			l1/data: false
			state/text: "False"
		][
			l1/data: true
			l1/data: true
			state/text: "True"
		]
		show [l1 state]
	]
]
Henrik
22-Apr-2012
[92x3]
caelum, take a look at the style code. the colors are likely embedded 
in it:

>> get in get-style 'led 'colors
== [0.255.0 255.0.0]

Then something like this:

stylize [
	led: led with [colors: [<your colors here>]]
]
should probably be STYLIZE/MASTER, sorry.
you can also do this:

view layout [led with [colors: [<your colors here>]]]
caelum
22-Apr-2012
[95]
Got it, exactly what I was looking for. Thanks.
Gregg
22-Apr-2012
[96x2]
You're ramping up fast sujoy. Most people don't get to using BIND 
for a long time. :-)
As Steeve has pointed out "it can be done" is *almost* always the 
answer with REBOL, and usually done in many ways. REBOL is great 
for practical use, as well as learning to think about problems in 
new ways.
Sujoy
24-Apr-2012
[98]
thanks Gregg. am loving rebol... :)
Endo
24-Apr-2012
[99]
you took the red pill then :)
Sujoy
24-Apr-2012
[100]
haha! looks like it Endo!
Gregg
24-Apr-2012
[101]
He's one of us now Endo. Next thing, he'll b3 wondering why every 
other programming language has only 6 or 8 datatypes and why they 
don't have a PARSE function. :-)
GrahamC
24-Apr-2012
[102x2]
has anyone written parse rules for phone numbers?   I need to setup 
a set of rules for international numbers, local numbers, cell numbers, 
1800 etc for use in asterisk and prevent users from making toll calls 
unless authorise
To make it easier I will strip out alll non-digits first