r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Anton
23-Feb-2008
[9316x2]
semi-flat: func [blk][
    while [not tail? blk][
        blk: either block? blk/1 [
            change/part blk blk/1 1
        ][
	    next blk
	]
    ]
    head blk
]

semi-flat [[1 ["one"]] [2 ["two"]] "other data"]
You can also use until instead of while:
semi-flat: func [blk][
    until [
	tail? blk: either block? blk/1 [
            change/part blk blk/1 1
        ][
	    next blk
	]
    ]
    head blk
]
[unknown: 5]
23-Feb-2008
[9318x2]
Yes Anton, thanks.
Anton, both of those functions you provided didn't seem to achieve 
what I was intending to do which was to format the block for easy 
selecting using 'select.
Anton
23-Feb-2008
[9320]
My example data contains "other data" which is probably confusing 
you, sorry.
[unknown: 5]
25-Feb-2008
[9321x3]
Anyone know what the discussions are regarding extending the alias 
function in REBOL3?  I have a bit ugly function that does something 
like that now.  What I'm talking about is the ability to alias for 
example find/only or find/case or instead of just find so that no 
refinement has to be supplied.  I submitted a wish for this some 
time ago and hoped it would make it in REBOL3 but don't know what 
is intended regarding that.
I checked the alpha and noticed that it still says it doesn't allow 
path! for its word argument.
Probably should move this question to R3 group
james_nak
26-Feb-2008
[9324]
Gregg, thanks I will look into the ICS method.
Louis
26-Feb-2008
[9325]
I have a script that sends out a newsletter to several hundred people. 
Sometimes (often) the mail server will disconnect before all the 
emails are sent. What is the best way to make the script reconnect 
and continue sending?
[unknown: 5]
26-Feb-2008
[9326x10]
Here is a little function I made to handle a situation I often find 
myself in.  Say you got three words and want to do something if one 
of the words has a value other than false or none.  But you may want 
to do something else if two words have a true value or maybe all 
three and then if also if none have a value such as a default.  This 
is a very flexible function I created to allow you to do that:
evals: func [blk blk2 /local r i l][
    r: 0
    i: 0
    l: length? blk2: reverse blk2
    foreach item blk [if get item [r: r + (2 ** i)] i: i + 1]
    while [l > 0][
        if r > (2 ** (l - 3)) [return first blk2]
        blk2: next blk2
        l: l - 1
    ]
    last blk2: head blk2
]
Now say you have some locals in a function that you want to check 
for any combination of them being used.  The evals function will 
let you do that.
the 'blk argument would be the locals (assuming that 'evals is a 
subfunction of  our function) that you want to pass to the evals 
function and the 'blk2 would be what to return if those values are 
true.  So for example, if I have the following locals in my function:

/any /only  


and say I have a default value of "default" that I want to return 
if /any or /only is not used.  Therefore, I pass the following:

evals [any only]["default" "any" "only" "any and only"]


it would then process the result.  This can be a very handy function.
>> any: true
== true
>> only: true
== true
>> evals [any only]["default" "any" "only" "any&only"]
== "any&only"
>> any: false
== false
>> only: true
== true
>> evals [any only]["default" "any" "only" "any&only"]
== "only"
>> any: false
== false
>> only: none
== none
>> evals [any only]["default" "any" "only" "any&only"]
== "default"
Pretty cool, eh?
the function shouldn't be used on more than three values just yet 
as I need to work on it a bit more to get it just right - I keep 
overlooking something.
ahhh I didn't subtract the values
[unknown: 5]
27-Feb-2008
[9336x3]
This is probably more practical:
evals: func [blk blk2 /local i r ][
    r: i: 0
    foreach item blk [if get item [r: r + (2 ** i)] i: i + 1]
    return select blk2 to-integer r
    select blk2 0
]
then you just supply the second block with the desired options you 
want combined.
Sunanda
29-Feb-2008
[9339]
Request for code (in any language) that correctly identifies leap 
years. Anyone want to do the inevitable one-liner?
http://leapyearday.com/hr/freecode.html
Pavel
29-Feb-2008
[9340x3]
Diy: func [year][either not equal? mod year 4 0 [return 365][ either 
equal? mod year 100 mod year 400 [return 366 ][return 365]]]
wrong
Diy: func [year][either not equal? mod year 4 0 [return 365][ either 
equal? zero? mod year 400 not zero? mod year 100 [return 365 ][return 
366]]]
should work
Izkata
29-Feb-2008
[9343x2]
Leap?: func [Y][return not not any [(Y // 400 = 0) all [(Y // 4 = 
0)  (Y // 100 <> 0)]]]
("not not" for changing 'none into 'false)
Geomol
29-Feb-2008
[9345]
I think, this works too:

diy: func [y][either y // 4 = 0 [either all [y // 100 = 0 y // 400 
<> 0] [365] [366]] [365]]
Sunanda
29-Feb-2008
[9346]
Here's my contribution....It may not be as fast as others, but it 
relies on REBOL's inbuilt definition of a leap year, so no need to 
duplicate logic:

leap?: func [date [date!] ][

  return not error? try [print 1 to-date rejoin ["29-02-" date/year]]


Seems to work on all border cases: 1899 --> 1904 ... 1999 --> 2004
  ]
Geomol
29-Feb-2008
[9347x7]
Sunanda, that's an interesting approach! :-)
The diy would then be:

diy: func [y] [either error? try [to-date join "29-02-" y] [365] 
[366]]
:-) REBOL is wonderful!
Does anyone send emails to them?
Smallest readable version, I can produce:

diy: func [y] [either attempt [to-date join "29-2-" y] [365] [366]]
oops, I exchanged 365 and 366. It should be:

diy: func [y] [either attempt [to-date join "29-2-" y] [366] [365]]
Leap year *is* tricky! :-)
And the leap? function:
leap?: func [year] [366 = diy year]
Sunanda
29-Feb-2008
[9354]
Nice work, guys.

I tried emailing them the link to this discussion, but their server 
is overload so it did not get through -- must be too many people 
sending them solutions in obscure languages :-)

http://www.rebol.org/cgi-bin/cgiwrap/rebol/aga-display-posts.r?post=r3wp157x9339
Gabriele
29-Feb-2008
[9355x2]
leap?: func [y] [2 = second to date! reduce [y 2 29]]
(probably not any better than the above)
[unknown: 5]
29-Feb-2008
[9357]
drop one character and change the to date! to to-date.  ;-)
Geomol
29-Feb-2008
[9358x2]
Nice one, Gabriele! It's a force in REBOL, that you can do things 
in many ways. So we often find a way, that suit us well. Of cource 
it can also be a little confusing and hard to find the 'best' way 
for you.
In most cases, we run circles around the other languages out there! 
:-)
Dockimbel
29-Feb-2008
[9360x6]
leap?: func [y][2 = second poke 29/02/2000 1 y]
A bit faster, but I'm not sure it would work correctly on big-endian 
platforms.
Alternative ways :
leap?: func [y /local c][c: 29/02/2000 c/year: y c/month = 2]

diy?: func [y][
    366 - to-integer to-logic any [
        positive? y // 4
        all [
            zero? y // 100
            positive? y // 400
        ]
    ]
]
(to-logic is useless here and should be removed)
Btw, using the =? operator instead of = for the ending test in 'leap? 
would make it more readable for non-rebolers.