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

World: r4wp

[Rebol School] REBOL School

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
[102x3]
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
I guess i should just make a rule for each type of call and then 
combine them.
Gregg
24-Apr-2012
[105x4]
Here's something for US phone numbers I did a long time ago
set 'parse-phone-num func [
        num [string!]
        /local  digit digits sep _ext_  ch nums pin ext
    ] [
        digit:  charset "0123456798"
        digits: [some digit]
        sep:    charset "()-._"
        _ext_:  ["ext" opt "." | "x"]

        nums: copy ""
        rules: [
            any [
                some [sep | copy ch digit (append nums ch)]
                | _ext_ copy ext digits
                | "pin" copy pin digits
            ]
            end
        ]
        either parse trim num rules 
            [reduce ['num nums 'ext ext 'pin pin]]
            [none]
    ]

    set 'well-formed-phone-number? func [num /local data] [
        either none? data: parse-phone-num num [false] [
            any [
                found? find [7 10] length? data/num
                all [11 = length? data/num  data/num/1 = #"1"]
            ]
        ]
    ]
And a formatter that goes the other way:
set 'format-phone-number func [
        num [string! object!] "String or object with /text value"
        /def-area-code area-code [string! integer!]
        /local left right mid obj res
    ] [
        left:  func [s len][copy/part s len]
        right: func [s len] [copy skip tail s negate len]
        mid:   func [s start len][copy/part at s start len]

        if object? num [obj: num  num: obj/text]

        res: either data: parse-phone-num num [
            ; discard leader if it's there.
            if all [11 = length? data/num  data/num/1 = #"1"] [
                data/num: right data/num 10
            ]
            rejoin [
                rejoin switch/default length? data/num [
                    7  [ compose [

                        (either area-code [rejoin ["(" area-code ") "]][])
                        left data/num 3 "-" right data/num 4
                    ]]
                    10 [[
                        "(" left data/num 3 ") "
                        mid data/num 4 3 "-" right data/num 4
                    ]]
                ][[data/num]]

                reduce either data/ext [[" ext" trim data/ext]] [""]

                reduce either data/pin [[" pin" trim data/pin]] [""]
            ]
        ][num]

        if obj [
            obj/text: res
            attempt [if 'face = obj/type [show obj]]
        ]
        res
    ]
GrahamC
24-Apr-2012
[109x2]
Ok, so this checks for legally formatted numbers.  Or formats numbers 
into the common format.
need to reboot .. clipboard not working.  When is openme coming :(
Gregg
24-Apr-2012
[111]
Yes. :-)
GrahamC
24-Apr-2012
[112x3]
p: format-phone-number "1800-123456"
== "(180) 012-3456"
might need a ittle tweaking for international numbers
How are international numbers formatted?  +181812345678  ?
Gregg
24-Apr-2012
[115x2]
As I said, it was just for US phone numbers. The +1 was not included, 
since it wasn't meant for dialing.
If you're asking how they're formatted in general, it depends.
GrahamC
24-Apr-2012
[117]
ok, so always 3 numbers in the first group if not international?
Gregg
24-Apr-2012
[118]
Yes.
GrahamC
24-Apr-2012
[119x2]
( we use 2 numbers for the first group unless it's cellular  when 
it's 3 or 4 )
can a number start with 1 ?
Gregg
24-Apr-2012
[121]
IIRC, some places use 4, grouping them into 2 sets of 2 for the area 
code.
GrahamC
24-Apr-2012
[122]
ohh ....