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

World: r3wp

[Core] Discuss core issues

GrahamC
29-Oct-2010
[246]
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.
Gregg
1-Nov-2010
[285]
Give me some numbers. Show me scenarios where it's a bottleneck. 


I should have a second log in here. P.O., because I'm sure I Piss 
Off a lot of people by always questioning Premature Optimization. 
:-)
Ladislav
1-Nov-2010
[286x3]
LOL
How about a LINE-NUMBER? function yielding a line-number of a string, 
would you want such a function to be a mezzanine?
(the function is available at

http://github.com/rebolsource/rebol-test

, BTW)
Gregg
1-Nov-2010
[289]
I want pretty much *everythihng* to be a mezzanine until we know 
the gains are worthwhile and will benefit enough people. That still 
gives us room to be subjective. ;-)
Ladislav
1-Nov-2010
[290]
I am the author, so if somebody different from myself wants to have 
the function as a mezzanine, fill in a CC ticket
Maxim
1-Nov-2010
[291]
gregg. such simple functions cannot be optimized in rebol simply 
because the lowest-level loops are VERY slow.  this is a simple function 
which requires no special treatment.


for such a function, the moment its written as a mezz, we can't say 
"premature" optimisation... its done.   the only improvement is to 
make it 20 times faster.
Gregg
1-Nov-2010
[292x2]
You're missing my point Max. I'm saying it doesn't need to be optimal 
yet, because we have no idea if it's worth optimizing.
Heck, we don't even have it as a standard function. :-)
Andreas
1-Nov-2010
[294]
You are also missing another point. Graham's original statement was 
meant to be ironic :)
Gregg
1-Nov-2010
[295]
I missed the irony. My apologies.