World: r3wp
[Core] Discuss core issues
older newer | first last |
Gabriele 19-Dec-2006 [6487x4] | graham, the paren is not needed there. |
chris: a trick i have seen: | |
if not all [ msg: "rebol.exe does not exist" exists? %rebol.exe msg: "rebol.exe is empty" 0 < size? %rebol.exe ] [make error! msg] | |
anyway, assert seems a good name to me. | |
Anton 19-Dec-2006 [6491] | Gabriele, yes I've used this trick, but it's a little uncomfortable. |
Dirk 21-Dec-2006 [6492] | Hi, syntax question: i want to insert a row into a mysql db: string-block: [ "value1" "value2" insert db [ "insert into table values (?,?)" string-block ] this fails (string-block is not evaluated i guess), but i dont know how to generate the following insert db [ "insert into table values (?,?)" "value1" "value2" ] (which works) using rejoin, remold, join, .. whatever. |
Maxim 21-Dec-2006 [6493] | merrry christmas :-) insert db compose [ "insert into table values (?,?)" (string-block) ] |
Dirk 21-Dec-2006 [6494x2] | and happy xmas to you! this works! how to factor out the "insert into .." string into a variable? stmt: "insert into .." insert db compose [ stmt (vals) ] does not work, neither does insert db reduce [ stmt vals ] which puzzles me ... |
btw. is this the right place to ask? | |
Maxim 21-Dec-2006 [6496x5] | this is the right place indeed :-) like so? insert db reduce compose [ stmt (vals) ] == ["insert into .." "value1" "value2" ] |
in REBOL since string datatypes evalutate to themselves, the result of the compose (which removes the outer block) will simply stay where they are . | |
I understand your issues trying to sort out all of the variations. remember that most series handling functions return the series at some point (its head, its tail, or somewhere in between). | |
that becomes the starting point for the next function "in the chain" | |
most series handling functions modify the series "in place" instead of copying them. This simplifies series manipulation by breaking down each step into little functions. | |
Dirk 21-Dec-2006 [6501] | hm, but: >> a == ["abc" "def"] >> compose [ "abc" (a) ] == ["abc" "abc" "def"] >> reduce [ "abc" a ] == ["abc" ["abc" "def"]] why is a block returned in reduce, but two strings (which i need) in compose. should be the same imho... |
Maxim 21-Dec-2006 [6502] | compose strips the outer block. |
Dirk 21-Dec-2006 [6503] | the block from (vals) ? |
Maxim 21-Dec-2006 [6504] | reduce simply evaluates each value in the block and inserts the result |
Dirk 21-Dec-2006 [6505] | i see |
Maxim 21-Dec-2006 [6506] | yep |
Dirk 21-Dec-2006 [6507] | this is not even mentioned in the tutorial i read... do more operators behave like that? |
Maxim 21-Dec-2006 [6508x4] | a common trick is to do this to unify a series as a block! which might also accept a string! : val: compose [(val)] this way, if val was originally a block, it stays that way, but if it was a string, its then inserted within one. Note that the above actually creates a new block... so that the original val (if it was a block) and the new one are not the same |
nope, its a special case for compose... and is one of its differentiating features. | |
also note that compose has a /deep refinement which is very handy | |
ex: a-big-view-block: [ button "press me" [print rejoin ["You have pressed " (val)]]] val: "the button" view layout compose/deep a-big-view-block | |
Dirk 21-Dec-2006 [6512x2] | neat (and important) |
im using rebol on sparc/solaris (for automation). not even perl installed on these boxes .-) | |
Maxim 21-Dec-2006 [6514] | note that in the above, if you didn't compose the block it would still work, since val would be evaluated on the fly... BUT if you have several windows opened at the same time and each new window displayed a different caption, then the above is necessary... otherwise changing the value of val will change ALL windows at the same time :-) which is a common error we all make at some point. |
Dirk 21-Dec-2006 [6515] | so the callback of the button will be bound to the value of 'val' at compose/deep time .. ? ok. |
Maxim 21-Dec-2006 [6516x3] | it will replace the (val) by its value at specific time |
another very good use of compose: time: now my-object: make object! compose [ name: "me" time: (time) ] without the compose, my-object/time will be none | |
actually it will raise an error since time within the context of the object, is not yet set. | |
Dirk 21-Dec-2006 [6519x2] | hm, isn't: my-object: make object! [ name: "me" time: now ] equivalent? |
ah, i see. | |
Maxim 21-Dec-2006 [6521] | yes... obviously, but sometimes, the value you want to set within your object is already used within the code that is populating it... it was just an example :-) |
Dirk 21-Dec-2006 [6522] | yeah, i see the difference. but i think the behaviour is a bit weird |
Maxim 21-Dec-2006 [6523] | why? |
Dirk 21-Dec-2006 [6524x3] | i would expect that time is identical to now after time: now but it's not. |
forget it. time: now my-object: make object! [ name: "me" mtime: time ] behaves the same ... | |
time: time was the problem | |
Maxim 21-Dec-2006 [6527x2] | yes exactly. that's what the compose allows. |
obviously one can say well, just use other words... but... its not always pretty... actually it rarely is. | |
Dirk 21-Dec-2006 [6529] | one last question: a: [ "a" "b" ] how to write/append %to.txt a so that a b <- with whitespace inbetween gets written? |
Maxim 21-Dec-2006 [6530x2] | btw, Ladislav has another more flexible function similar to compose... its called 'BUILD ( http://www.fm.vslib.cz/~ladislav/rebol/) |
write/append %to.txt form a | |
Dirk 21-Dec-2006 [6532] | woot! thx |
Maxim 21-Dec-2006 [6533] | glad I can help :-) |
Dirk 21-Dec-2006 [6534] | should have read strings, not blocks in the reference .... Thanx for you help Maxim. Have to drive home now ... |
Anton 26-Dec-2006 [6535] | Dirk, check out compose/ONLY, eg: >> blk: [1 2 3] compose/only [hello (blk)] == [hello [1 2 3]] |
Anton 28-Dec-2006 [6536] | I want to speed up access to a block of objects (unassociated) for a search algorithm. Should I use LIST! or HASH! ? It's a growing list of visited objects, and I'm searching it each time to see if the currently visited object has already been visited. |
older newer | first last |