World: r3wp
[Core] Discuss core issues
older newer | first last |
Brock 4-May-2005 [1007x4] | show: func [ d /local alpha ][ get-city: [thru "City:" copy city to "^/"] get-stateprov: [thru "Stateprov:" copy stateprov to "^/"] get-country: [thru "country:" copy country to "^/" to end] parse d [get-city get-stateprov get-country] print [ "City: " a ] print [ "StateProv: " b ] print [ "Country: " c ] ] |
If you didn't know the order of the data being provided to you then you could generalize the code even further... here are the two lines that would change.... get-country: [thru "country:" copy country to "^/"] ; remove "to end" parse d [any [get-city get-stateprov get-country] to end] ; added 'any block and "to end" | |
I WISH I WAS ABLE TO DELETE... I made a mistake <blush>, I forgot to remove your old variable names and there is a small error in the code I've posted above. | |
;here's a working show... but didn't easily come across a solution to allow for an unkown order of items to find show: func [ d /local alpha ][ get-city: [thru "City:" copy city to "^/"] get-stateprov: [thru "Stateprov:" copy stateprov to "^/"] get-country: [thru "country:" copy country to "^/"] parse d [get-city get-stateprov get-country to end] print [ "City:" tab trim city newline "Stateprov:" tab trim stateprov newline "Country:" tab trim country newline ] ] | |
MikeL 5-May-2005 [1011] | Brock, A good example to look at for parsing is the make-doc script. Carl has updated with makedoc2.r available at this address http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=makedoc2.r but it is doing what your are asking about for the make doc source script which can have tags starting with === or --- followed by some text and a newline. The key is "rules: [some commands]" Have a look at it. |
Brock 6-May-2005 [1012] | Will do. |
Gordon 6-May-2005 [1013x2] | Hello; I'm wondering if there is a more efficeint way to assign values directly to a block of variables. My example involves reading lines from a file and assigning them one at a time to each variable. Here is the line format: LineFormat: [DateStr Manufacturer MF_Part TD_Part Desc Price1 Price2 Retail Stock Misc] Data: read/lines Filename Str: first Data Then I go though the String 'Str' and do the assigns DateStr: First Str Manufacturer: Second Str MF_Part: Third Str TD_Part: Fourth Str Desc: Fifth str Price1: skip Str 5 Price2: skip Str 6 Retail: skip Str 7 QOH: skip Str 8 Misc: skip Str 9 Am I missing something obvious about assigning one block of values to another block of variables? |
Oops forgot a step; should be: Data: read/lines Filename DataStr: first data Str: parse/all DataStr none (the parse splits the lines of data into a block of values) | |
DideC 6-May-2005 [1015x3] | SET is your friend ! set [SatStr Manufacturer MF_part TD_Part Desc ...] Str |
ie: | |
a: [24 "Hello" 1.2.3] set [b c d] a print [d c b] | |
Gordon 6-May-2005 [1018x2] | I'll give it a try. Thanks - BRB |
Beauty! Thanks DideC | |
DideC 6-May-2005 [1020] | no problem |
Micha 7-May-2005 [1021x4] | REBOL [Title: "proxy multiple" ] print "start-multiple" list: [] proxy: make object! [ host: 24.186.191.254 port-id: 29992 ] ph: func [port][ switch port/locals/events [ connect [insert tail list port ping: to-integer (now/time - port/date ) * 1000 port/date: now/time print [ "open ping: " ping ] ] close [ remove find list port init ping: (now/time - port/date ) * 1000 print ["close ping: " ping ] close port ] ] false ] stop: func [] [ clear system/ports/wait-list forall list [close first list ]] init: func [ /local port ][ port: make port! [ scheme: 'atcp host: proxy/host port-id: proxy/port-id awake: :ph date: now/time ] open/no-wait/binary port insert tail system/ports/wait-list port ] set: func [ h p ] [ proxy/host: h proxy/port-id: p ] send: func [ port ][ port/date: now/time insert port join #{0401} [debase/base skip to-hex 80 4 16 to-binary 193.238.73.117 #{00}] ] |
plis help ? | |
init error ! | |
>> init ** User Error: No network server for atcp is specified ** Near: port: make port! [scheme: 'atcp host: proxy/host port-id: proxy/port-id awake: :ph date: now/time] open/no-wait/binary >> | |
Sunanda 7-May-2005 [1025] | Any easy way of doing this? (I got a loop, but it feels there ought to be a more elegant way) a: "123123123" b: "12312345678" print skip-common a b "45678" ;; string after common part of both strings |
Gordon 7-May-2005 [1026] | Hello; How do you convert a letter (ASCII) to it's hex equivalent? I've tried to-hex but it wants an integer!? You would think it would be easier than: print to-integer to-string to-hex to-integer to-decimal to-char "a" which works but there has got to be an easier way. |
Tomc 7-May-2005 [1027] | >> to-hex to integer! #"A" == #00000041 |
Sunanda 7-May-2005 [1028] | Gordon, your method only works for chars than happen to map to decimals. Try this for an error: print to-integer to-string to-hex to-integer to-decimal to-char "M" Variant on Tom's to produce the same result as yours (may not work with 64-bit REBOL) form skip to-hex to-integer first "a" 6 |
Gordon 7-May-2005 [1029] | Thanks Tomc and Sunanda |
Tomc 7-May-2005 [1030x2] | >> copy/part tail to-hex to integer! to char! "Z" -2 == #5A |
unfortinatly for me we dont have a 64 bit rebol | |
Gordon 7-May-2005 [1032] | Does anyone? |
Tomc 7-May-2005 [1033x2] | or unicode |
not that I know of | |
Gordon 7-May-2005 [1035] | Thanks again for your help |
Sunanda 7-May-2005 [1036x2] | Quick work there Gordon: http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=char-to-hex.r Thanks for the name check :-) |
And I see you've solved the potental 64-bit / variable hex problem | |
Gordon 7-May-2005 [1038x5] | Well actually Tomc made the suggestion. |
Sorry for the slow reply but if I leave Altme open it keeps stealing focus from my coding program . I have to shut Altme down so I can work. | |
Here's another odd one that has be puzzled (Notice that appending something to the Writefile variable, also appends it to the DateStr variable! Very Strange!) >> WriteFile: "WriteFileName_2005-05-07" == "WriteFileName_2005-05-07" >> DateStr: skip tail WriteFile -10 == "2005-05-07" >> Success: append WriteFile "_Parsed.txt" == "WriteFileName_2005-05-07_Parsed.txt" >> probe DateStr 2005-05-07_Parsed.txt == "2005-05-07_Parsed.txt" | |
Nevermind. I think I should have used a copy of Writefile. DateStr must be a subset of WriteFile variable because of the reference to it's tail. | |
Yep, it just needed a copy as in: >> DateStr: skip tail copy WriteFile -10 == "2005-04-11" | |
Tomc 8-May-2005 [1043] | gordon: home-icon - settings - options -unset "activate window on new message" |
Gordon 8-May-2005 [1044] | Thanks Tomc; that should do it. |
Micha 9-May-2005 [1045x3] | how to decode this url ? |
input: uggc%2Fjungvfzlvc.pbz | |
output: http://whatismyip.com | |
Anton 9-May-2005 [1048] | rot13: func [s [string!] /local result top][ result: copy s repeat n length? s [ top: either s/:n >= #"a" [97][65] ; determine upper or lowercase if (i: s/:n - top) < 26 [ ; only 26 letters in alphabet affected i: i + 13 // 26 ; perform rot13 poke result n to-char top + i ; insert new letter ] ] result ] |
Gabriele 9-May-2005 [1049x5] | sunanda: i can only think of: |
>> index? find (as-binary a) xor as-binary b complement charset "^(00)" == 7 | |
though, i'm not sure it's an easy way, and it is probably overkillif a and b are "big". | |
another option would be to try with parse, though it's gonna boil down to some kind of loop anyway. | |
>> parse a [any [(char: b/1) char (b: next b)]] == false >> b == "45678" | |
Janeks 9-May-2005 [1054] | How to set correctly progress function for read-net? Or what causes following error and : >> myProgr: func [ tot bt ] [ print bt / tot ] >> read-net/progress to-url "http://maps.dnr.state.mn.us/cgi-bin/mapserv36?map=/usr/loca l/www/docs/mapserver_demos/tests36/expressions/test.map&map_counties_class_expression=(% 5bAREA%5d %3e 7577272785.15339)&layer=title&map_title_class_text=Counties+Larger+Tha n+Itasca+County&mode=map" :myProgr 0.425625 ** Script Error: not is missing its value argument ** Where: read-net ** Near: all [:callback size not callback size length? buffer data: true break] not data >> source read-net read-net: func [ {Read a file from the net (web). Update progress bar. Allow abort.} url [url!] /progress callback {Call func [total bytes] during transfer. Return true.} /local port buffer data size ][ vbug ['read-net url] if error? try [port: open/direct url] [return none] size: to-integer any [port/locals/headers/content-length 8000] buffer: make binary! size set-modes port/sub-port [lines: false binary: true no-wait: true] until [ if not data: wait [60 port/sub-port] [data: true break] if data: copy port/sub-port [append buffer data] all [:callback size not callback size length? buffer data: true break] not data ] close port if not data [buffer] ] >> |
Gabriele 9-May-2005 [1055] | is your callback function returning a value? i think it should return true normally, or false if you want to cancel the download. |
Allen 9-May-2005 [1056] | Use request-download as a guide. It has everything you need to know. you should be able to substitute read-thru with read-net if you wish. |
older newer | first last |