Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Imbedding rebol code in a dialect

 [1/3] from: tim::johnsons-web::com at: 24-Sep-2002 16:44


Hello All: <wink>I'm feeling guilty about buggin Andrew at home</wink>, so am baring my ignorance of dialecting to the whole world here.. I am working with Andrew's 'ML dialect, and have the following code segment which extracts data from a cgi post, and saves it in hidden fields. Code below: print ml compose/deep[ form/action/method (cgl[get path thru "process"]) "POST"[ ( foreach field required-fields[ value: cgl[get value field] ml[input/type/name/value "hidden" (field) (value)] ] ) ] ] ;end 'ML ; Where 'required-fields is a block of values, matches are found on ; all values, but only the last match is being shown in the ; resulting hidden field required-fields: ["First Name" "Last Name" "Street Address" "State/Province" "Country" "Phone" "E-mail" Password "Login" "Subscription Type" "City" "Zip/Postal Code"] My guess is that I am not using 'compose correctly or my parenthesis are incorrectly placed. Any other ideas? TIA -- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

 [2/3] from: al:bri:xtra at: 25-Sep-2002 16:24


Tim wrote:
> print ml compose/deep[ > form/action/method (cgl[get path thru "process"]) "POST"[
<<quoted lines omitted: 7>>
> ] ;end 'ML > My guess is that I am not using 'compose correctly or my parenthesis are
incorrectly placed. Any other ideas? Just need to return a block! of: input/type/name/value "hidden" (Field) (Value) for each 'field, in the paren! just inside the 'form block! value. I'd use my 'Map function here ('cause it returns a block!). Something like: print ML compose/deep [ form/action/method (cgl[get path thru "process"]) "POST" [( Map required-fields function [Field [string!] [Value] [ Value: cgl [get Value Field] ; This line seems a bit odd! compose/deep [ input/type/name/value "hidden" (Field) (Value) ] ] )] ; Note the _two_ closing brackets! ] I've attached my very latest 'Map function, with the necessary 'Arguments function. Andrew Martin ICQ: 26227169 http://valley.150m.com/ -><- -- Attached file included as plaintext by Listar -- -- File: Map.r Rebol [ Name: 'Map Title: "Map" File: %"Map.r" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Web: http://valley.150m.com Date: 24/September/2002 Version: 1.3.0 Purpose: {Maps or applies the function to all elements of the series.} Category: [util 1] Acknowledgements: [ "Joel Neely" "Ladislav" ] Example: [ Map func [n [number!]] [n * n] [1 2 3] ;== [1 4 9] Map [1 2 3] func [n [number!]] [n * n] ;== [1 4 9] Map [1 2 3 4 5 6] func [a] [print [a]] ;1 ;2 ;3 ;4 ;5 ;6 ;== [] Map [1 2 3 4 5 6] func [a b] [print [a b]] ;1 2 ;3 4 ;5 6 ;== [] Map [1 2 3 4 5 6] func [a b c] [print [a b c]] ;1 2 3 ;4 5 6 ;== [] ] Requires: %Arguments.r ] Map: function [ {Maps or applies the function to all elements of the series.} [catch] Arg1 [any-function! series!] Arg2 [any-function! series!] /Only "Inserts the result of the function as a series." ][ Result Results Function Series ][ throw-on-error [ any [ all [ any-function? :Arg1 series? :Arg2 (Function: :Arg1 Series: :Arg2) ] all [ any-function? :Arg2 series? :Arg1 (Function: :Arg2 Series: :Arg1) ] throw make error! reduce [ 'script 'cannot-use rejoin [ {"} mold 'Map " " mold type? :Arg1 {"} ] rejoin [ {"} mold type? :Arg2 {"} ] ] ] Results: make Series length? Series do compose/deep [ foreach [(Arguments :Function)] Series [ if all [ not unset? set/any 'Result Function (Arguments :Function) not none? Result ] [ (either Only ['insert/only] ['insert]) tail Results :Result ] ] ] Results ] ] -- Attached file included as plaintext by Listar -- -- File: Arguments.r Rebol [ Name: 'Arguments Title: "Arguments" File: %"Arguments.r" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Web: http://valley.150m.com Date: 31/August/2002 Version: 1.0.1 Example: [ Arguments :Arguments ; [F] ] Purpose: "Returns the arguments of the function as a block." Category: [util script 5] ] Arguments: function [ "Returns the arguments of the function as a block." F [any-function!] ] [ Arguments ] [ Arguments: make block! 2 foreach Argument pick :F 1 [ if refinement? :Argument [ break ] append Arguments :Argument ] Arguments ]

 [3/3] from: tim:johnsons-web at: 25-Sep-2002 8:12


Hello Martin: * Andrew Martin <[Al--Bri--xtra--co--nz]> [020924 20:54]:
> Just need to return a block! of: > input/type/name/value "hidden" (Field) (Value)
<<quoted lines omitted: 4>>
> Map required-fields function [Field [string!] [Value] [ > Value: cgl [get Value Field] ; This line seems a bit odd!
'cgl is a dispatch function for the 'cgi object. I got tired of typing forward slashes :-)
> compose/deep [ > input/type/name/value "hidden" (Field) (Value)
<<quoted lines omitted: 4>>
> I've attached my very latest 'Map function, with the necessary 'Arguments > function.
Thanks! I'll check that out. In the meantime, I wrote a quick a dirty help function: cgi-to-hidden: func[v[block! string!] /local str val][ either string? v[ if not val: cgl[get value v][val: ""] str: copy ml[input/type/name/value "hidden" (v) (val)] ][ str: copy "" repeat name v[ if not val: cgl[get value name][val: ""] append str ml[input/type/name/value "hidden" (name) (val)] ] ] ] ; and take note that cgl[get value name] <=> cgi/get/value name ; and for snippet of the calling code form/action/method (cgl[get path thru "process"]) "POST"[ (cgi-to-hidden required-fields) (cgi-to-hidden optional-fields) ; etc, etc, .... <sigh>so much to do, so much to learn</sigh> Thanks again Andrew. -- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted