World: r3wp
[Core] Discuss core issues
older newer | first last |
Anton 22-May-2006 [4685x3] | ok, hang five. |
Paste this into your console: | |
make-template-context: func [ template /local words spec ][ words: remove-each val to-block template [tag? val] spec: words forall spec [spec/1: to-set-word spec/1] append spec none context spec ] eval-template: func [ template-ctx code /local err ][ unset bind next first template-ctx template-ctx ; unset all words in the context do bind code template-ctx ; do the code ; Check if any tags were not set if find next second template-ctx unset! [ ; were any tags not set ? print "Some tags were not set!" foreach word next first template-ctx [ if not value? in template-ctx word [ print [word "is unset!"] ] ] ] ] ; now test template: "<html><head><title> title </title></head><body>tag1 tag2 tag3</body></html>" template-context: make-template-context template eval-tags: [ title: "web page" tag1: "tag1" tag2: "tag2" tag3: "tag3" ] eval-template template-context eval-tags ; <- this sets all expected tags and is ok eval-template template-context [] ; <- this doesn't set any tags so will complain and show all unset tags | |
Joe 22-May-2006 [4688] | I am using altme on linux. How do I get the clipboard to work ? |
Henrik 22-May-2006 [4689] | I think by using the middle mouse button |
Joe 22-May-2006 [4690x2] | nope, clipboard is broken in linux |
anton, thanks for your example, it's quite useful | |
Anton 22-May-2006 [4692] | You're welcome. |
Joe 22-May-2006 [4693x2] | ZZ |
didn't mean to type it | |
Frank 22-May-2006 [4695] | Clipboard on linux : ctrl-v in altme and middle mouse button in a text editor, it works for me |
Joe 22-May-2006 [4696] | Frank, yes thanks. For me is ctrl-C + middle mouse |
Henrik 22-May-2006 [4697] | Why can't I find paths in a loadable block? >> t: [x/y] == [x/y] >> type? first t == path! >> find t 'x/y == none >> find t to-path 'x/y == none |
Anton 23-May-2006 [4698] | I think the answer is: "because there is a bug." |
BrianH 23-May-2006 [4699x2] | Paths are structures like blocks. Find doesn't do structure analysis on block types like that - it just tries to determine if the exact same path is there, not another that resembles it. |
Use find/only and your path! will be found. | |
Henrik 23-May-2006 [4701x2] | >> t: [x/y] == [x/y] >> type? first t == path! >> type? 'x/y == path! >> equal? 'x/y first t == true One would think that find would be able to find it anyway |
ah! thanks | |
BrianH 23-May-2006 [4703x2] | >> find/only [x/y] 'x/y == [x/y] find [x y] 'x/y == [x y] |
Find can be unexpectedly fun at times. | |
Henrik 23-May-2006 [4705] | yes, it's very fun especially when you are on a time limit :-) |
Anton 23-May-2006 [4706] | Brian is right, the more complex "object" types are compared using same?: >> equal? 'x/y 'x/y == true >> same? 'x/y 'x/y == false |
BrianH 23-May-2006 [4707x3] | When searching in a string type for any string type, the type is converted. Same for block types. And path! is a block type. |
The only way to avoid the conversion is to use /only. | |
I was wrong earlier about the reason Henrik's find didn't work. | |
Anton 23-May-2006 [4710] | yes, my initial reply was a bit hasty too. |
Ashley 23-May-2006 [4711x2] | Don't know whether this has been discussed / RAMBOed yet, but I think a smarter reduce (either a refinement or another word) which could handle: reduce [now then] instead of requiring: reduce [now 'then] or compose [(now) then] would make writing dialects a lot easier as unset! is rarely a legitimate value within a dialect (i.e. I'd like to reduce blocks before parsing and words without a value should just be left as is). |
Something like: reduce2: make function! [ block [block!] "Block to reduce" /deep "Reduce nested blocks" /local blk "Evaluates a block of expressions, skipping words without a value, and returns a block." ] [ blk: copy [] foreach word block [ either block? word [ either deep [ insert/only tail blk reduce2/deep word ] [insert/only tail blk word] ] [insert tail blk either value? word [do word] [word]] ] blk ] >> reduce2 [red x now now/date (1 + 1) [red x now now/date (1 + 1)]] == [255.0.0 x 24-May-2006/13:12:14+10:00 24-May-2006 2 [red x now now/date (1 + 1)]] >> reduce2/deep [red x now now/date (1 + 1) [red x now now/date (1 + 1)]] == [255.0.0 x 24-May-2006/13:12:26+10:00 24-May-2006 2 [255.0.0 x 24-May-2006/13:12:26+10:00 24-May-2006 2]] but as a native! and able to handle funcs with args (e.g. reduce2 [print "hi"]). | |
Ashley 24-May-2006 [4713] | Here's a different approach to get the result I'm after: cast: make function! [ block [block!] "Block to cast" words [block!] "Words to convert into literal words" /local blk word "Casts nominated words within a block into literal words." ] [ blk: copy [] repeat i length? block [ insert/only tail blk either find words pick block i [to lit-word! pick block i] [pick block i] ] blk ] >> cast [area red button green 'btn blue] [area button] == ['area red 'button green 'btn blue] >> reduce cast [area red button green 'btn blue] [area button] == [area 255.0.0 button 0.255.0 btn 0.0.255] |
BrianH 24-May-2006 [4714x2] | >> reduce/only [area red button green 'btn blue] [area button] == [area 255.0.0 button 0.255.0 'btn 0.0.255] |
Does that do what you need? | |
Ashley 24-May-2006 [4716] | Doh! I'm an idiot. I even read the help text on reduce ... but failed to read the text associated with the words refinement. Thanks for that, that is one refinement I'm *never* going to forget now. ;) Please disregard my previous postings. |
BrianH 24-May-2006 [4717] | Yeah, I get that feeling here a lot too :) |
Geomol 24-May-2006 [4718] | REBOL keeps surprise us again and again! :-) |
BrianH 24-May-2006 [4719] | I was a little surprised that the lit-word didn't turn into a word. That could be useful. I'm going to do some experiments to see what else reduce/only doesn't do. Should be fun. |
Rebolek 24-May-2006 [4720] | Why I am not able to OPEN file which I can READ ? |
Graham 24-May-2006 [4721x2] | Example? |
'read must 'open a file | |
Ladislav 24-May-2006 [4723] | Open/read may be the difference |
Rebolek 24-May-2006 [4724] | Ladislav yes, that was the problem, thanks |
JaimeVargas 24-May-2006 [4725] | Ashley, but reduce/only doesn't perform according to your initial spec "Evaluates a block of expressions, skipping words without a value, and returns a block." >> reduce/only [now then] ** Script Error: then has no value |
Anton 24-May-2006 [4726x2] | Huh? that's not the error I get: >> reduce/only [now then] ** Script Error: reduce expected words argument of type: block none ** Near: reduce/only [now then] |
Ah but maybe that's still your point - not what Ashley asked for. | |
Volker 24-May-2006 [4728] | Docu is wrong. it does not reduce words in the /only block. But it also rejects functions. so >> reduce/only[then][then] == [then] but it also rejects functions, here unfortunally: >> reduce/only[now][] ** Script Error: Invalid argument: now because of security-reasons (draw-blocks from untrusted code). |
Ashley 24-May-2006 [4729] | but reduce/only doesn't perform according to your initial spec True, on two counts: 1) It doesn't evaluate expressions (even if parenthesized) 2) You have to predetermine what words to ignore (less of an issue for dialects) I still can't see a simple way of doing the following: >> reduce [b: button red form now/date] ** Script Error: button has no value ** Near: b: button red form now/date >> reduce/only [b: button red form now/date] [button] ** Script Error: Invalid argument: form ** Near: form now/date >> reduce/only [b: button red (form now/date)] [button] == [b: button 255.0.0 (form now/date)] although at least the last case gets most of the way there. What I'd really like is: >> reduce/ignore [b: button red form now/date] == [b: button 255.0.0 "25-May-2006"] |
Ladislav 25-May-2006 [4730] | I am using my BUILD dialect http://www.fm.tul.cz/~ladislav/rebol/build.r to do it as follows: >> build [b: button ins red ins form now/date] == [b: button 255.0.0 "25-May-2006"] or, another alternative: >> build/with [b: button red form now/date] [red: system/words/red form: get in system/words 'form] == [b: button 255.0.0 "25-May-2006"] |
Gabriele 25-May-2006 [4731] | Use do/next in the parse rule. (that's the reason I suggested the DO command for parse some time ago...) |
Ashley 25-May-2006 [4732x2] | Not sure I understand, a small example would help. ;) |
Or was your comment intended for Ladislav? | |
Cyphre 25-May-2006 [4734] | Ashley: reduce /only -- Only evaluate words and paths, not functions So the results you are getting above seems logicalto me. |
older newer | first last |