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

World: r3wp

[Core] Discuss core issues

GrahamC
28-Oct-2010
[235]
so return those in a block where there exists more than one?
Maxim
28-Oct-2010
[236]
yep.
GrahamC
28-Oct-2010
[237x2]
which is essentially what I was trying to do above
what instances have you needed this?
Maxim
28-Oct-2010
[239x2]
but its so usefull in simplifying many other loops and algorithms.
when managing data sets, you often want to know what is unique "within" 
that set.   

duplicates and singletons are often-required things you want to know 
about a data set.
GrahamC
28-Oct-2010
[241]
i guess make a wish on curecode for R3
Maxim
28-Oct-2010
[242x2]
yes... I just thought about that.
I will.
GrahamC
29-Oct-2010
[244x3]
Has anyone a simple algorithm for calculating the last day of a month? 
 Or is a lookup table easiest?


get-end-month: func [ d [date!] /local tmp ][ tmp: d while [ tmp/month 
= d/month ][ tmp: tmp + 1 ] tmp ]
get-end-month: func [ d [date!] /local tmp ][ tmp: d while [ tmp/month 
= d/month ][ tmp: tmp + 1 ] tmp - 1 ]
get-end-month: func [ d [date!] /local tmp ][ tmp: d  tmp/day: 28 
while [ tmp/month = d/month ][ tmp: tmp + 1 ] tmp - 1 ]
Gregg
29-Oct-2010
[247]
set 'last-day-of-month func [date /local d] [
    d: date
    d/day: 1
    d/month: d/month + 1
    d: d - 1
    d
]
GrahamC
29-Oct-2010
[248]
nice
Henrik
30-Oct-2010
[249]
>> append [] 'now/precise
== [now precise]

is there a better way?
Sunanda
30-Oct-2010
[250]
Is this better? To get an unevaluated now/precise into a block:
    append [] [now/precise]
Henrik
30-Oct-2010
[251x3]
possibly...
found a different way, so won't be needed.
I wanted a nice way to produce fragmented message strings that will 
be translated later, using a TRANSLATE function. So I made this function:

tell: func [blk /local out s] [
	out: make string! 10000
	parse blk [
		any [
			[
				set s string! (append out translate s)

    | to any-type! copy code [to string! | to end] (append out to string! 
    reduce [#"'" mold/only do code #"'"])
			]
			(append out #" ")
		]
	]
	join trim out #"."
]

>> file: what-dir
== %/c/program files/rebol/view/

>> tell ["File" file "cannot be found"]
== {File '%/c/program files/rebol/view/' cannot be found.}
Ladislav
30-Oct-2010
[254]
>> append/only [] 'now/precise
== [now/precise]
Henrik
30-Oct-2010
[255]
interesting, thanks
Gabriele
31-Oct-2010
[256]
Henrik, I don't think that's nice, because you can't really translate 
"File" and "cannot be found" separately. Don't expect all languages 
to have the same grammar structure etc.
Henrik
31-Oct-2010
[257x2]
Gabriele, probably not, but the language system, I'm working with 
works like this.
a better one would probably input the string like:

File %1% cannot be found.

Maybe I should do that...
Gabriele
31-Oct-2010
[259]
What I did for the network detective was "File <file> cannot be found." 
See SUBSTITUTE in http://www.colellachiara.com/soft/libs/utility.r
Henrik
31-Oct-2010
[260]
ok, thanks
Gabriele
31-Oct-2010
[261]
(I think that <filename> or %filename% etc. helps the translator 
a lot more than %1% or anything like that. Of course, Qtask uses 
%1%. :-)
Henrik
31-Oct-2010
[262x2]
how do you determine the order without referring to the tag twice?
ok, I see what you're doing....
GrahamC
31-Oct-2010
[264x3]
Anyone got a suggestion on how to flatten the results of a SQL query.
Got [ [ "xxx" ] [ "yyy" ] [ "zzz" ]]
and want 
[ "xxx" "yyy" "zzzY ]
now
to-block form [ [ "xxx" ] [ "yyy" ] [ "zzz" ]]

does not work ... due to Rebol evaluating the contents
sure I could iterate over the whole lot and create a new block ...
Andreas
31-Oct-2010
[267x2]
>> collect [foreach item [["xxx"] ["yyy"] ["zzz"]] [keep item]]  
   
== ["xxx" "yyy" "zzz"]
Even simpler:
>> map-each item [["xxx"] ["yyy"] ["zzz"]] [first item]
== ["xxx" "yyy" "zzz"]
GrahamC
31-Oct-2010
[269]
heh .. not used map-each or collect before .. are these in R2 ?
Andreas
31-Oct-2010
[270x2]
in 2.7.7 at least
Part of R2/Forward.
GrahamC
31-Oct-2010
[272]
Ah... I'm using 2.7.6 and they're not there
Andreas
31-Oct-2010
[273]
Then just write the single line that is flatten :)
GrahamC
31-Oct-2010
[274x3]
done that ...
I thought there might be some other trick I could use
well,  I will use the to-block form and if that errors out drop back 
to flatten
PeterWood
31-Oct-2010
[277x2]
Try parse, it should be quick:


>> parse [["xxx"] ["yyy"] ["zzz"]] [(f: copy []) any [set b block! 
(append f first b)]]                                             
                           
== true

>> 
f
== ["xxx" "yyy" "zzz"]
Of course, it would be quicker using insert back tail but that would 
have made the one-liner longer ;-)
Andreas
31-Oct-2010
[279]
Nevermind, it's already verbose enough :)
GrahamC
31-Oct-2010
[280]
parse it is then!
Andreas
31-Oct-2010
[281]
Speed, speed, speed! :)
GrahamC
31-Oct-2010
[282]
well, I thought we should really have a native for this ....  where's 
Cyphre's JIT compiler??
Gregg
1-Nov-2010
[283]
Why should it be native?
Maxim
1-Nov-2010
[284]
cause its going to be A LOT faster and for things like database queries, 
this can become quite a bottleneck.