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

ANN: custom-types.r

 [1/16] from: g:santilli:tiscalinet:it at: 14-Mar-2003 10:30


Hello all, I decided to release an alpha version of custom-types.r. You can find it in: http://www.rebol.it/giesse/custom-types.r This version does not patch the global native actions; instead, it creates the ACTIONS* object with all the patched actions and sets the patched actions in the global context with a * suffix (i.e. PICK* etc.). To make a new type you just need to do: my-type!: make custom-type! [ ; you can place any data you require here actions [ ; you define the actions here ] ] You can see an example custom type in: http://www.rebol.it/giesse/complex.r Please note that custom-types.r requires subfunc.r from Ladislav. It just expects to find it in the same directory (along with tfunc.r that is required by subfunc.r). Also note that Ladislav's subfunc.r uses his function INCLUDE to call tfunc.r; you could get it too, or just replace the "include %tfunc.r" line in subfunc.r with "do %tfunc.r". On a side note, I've also uploaded: http://www.rebol.it/giesse/compile-rules.r it has a number of differences from the one previously described in my REP, and is not yet fully documented; it obsoletes dialect-framework.r, so if you were playing with it, you should probably try this new script. Here's a short note on the new PARSE commands: INTERPRET WITH <subrule> evaluate any control or iteration function (as well as function definitions and user defined functions). <subrule> is the rule applied to the blocks evaluated by the functions. IF <condition> <rule> condition has to be a paren!. If it results into true (actually, not none or false), rule is applied. EITHER <condition> <true-rule> <false-rule> condition has to be a paren!. Depending on the result of its evaluation, true-rule or false-rule is applied. DO <word> <rule> the next expression at the current position is evaluated (via DO/NEXT); rule is applied to the result (i.e. to a block containing the result as its first and only element), and if it matches the word is set to the result; if it does not match, an ERROR! is fired. THROW <message> <rule> rule is applied; if it matches, parsing continues normally; if it does not match, an ERROR! is fired using the supplied message (has to be a string). I hope to write a better doc for it soon; I will also update and submit my REP (I hoped to get more comments on it, tough...) to RT. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [2/16] from: bry::itnisk::com at: 14-Mar-2003 11:23


Here's a question, since I never have an opportunity to just look through anything in my current productivity cycle and need to reference things for future reference. Can this be used to make types which are xml fragments? For example could one specify from this that a type PersonName consisted of <name> <firstName>John</firstName> <surname>Doe</surname> </name> If so I think one of the most important steps to building an xml-schema implementation in Rebol might have been taken.

 [3/16] from: g:santilli:tiscalinet:it at: 14-Mar-2003 12:41


Hi bryan, On Friday, March 14, 2003, 11:23:00 AM, you wrote: b> Can this be used to make types which are xml fragments? I'm not sure I understand what you mean, but I think the answer is no. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [4/16] from: bry:itnisk at: 14-Mar-2003 14:58


b>> Can this be used to make types which are xml fragments?
>I'm not sure I understand what you mean, but I think the answer is >no.
I was thinking about WXSDL (W3C Xml Schema Definition Language) and its way of handling datatypes. To give a short and highly incomplete run-through: You can define your own types which are xml instances in a document, then you can refer to these types in building new types. The xml tag name could be a complex type consisting of the following two tags: <firstName>John</firstName> <surname>Doe</surname> the tags firstName and surname could be defined as being of type xsd:string(which is, as it no doubt indicates, a string datatype). In xml schema the idea is (personally don't know how good of an idea I find it) that you can later define a type CompanyPersonName which inherits from PersonName but also requires a tag <addressableAs>Mr.</addressableAs> which could have a datatype of an enumeration list of possible values: mr. mrs. Ms. Dude. Well maybe not the last. The reason why I was thinking about it was that, although I hate WXSDL it is, just from its prominence of use in .Net and various Microsoft products/initiatives - not to mention governmental initiatives (governments tending to blindly require that one use W3C stuff), becoming quite useful to know and use. I remember that someone asked about the possibility to do a schema to rebol conversion, which I thought would not be especially useful, however if the following would allow defining types that were xml instances then one would be somewhat begun on the road to doing this (another thing that would be required would be support for Unicode and Regex however). What I was interested in at the time of the schema to rebol discussion involved having something like in .Net where one can have runtime conversion between WXSDL datatypes and .Net datatypes.

 [5/16] from: brett:codeconscious at: 15-Mar-2003 14:20


Hi Gabriele, I think that your ideas are very useful. Throw. I really like the use of errors to communicate back important information (esp. the use of the Near error field). I wonder whether parse could have some default functionality like you have made that could be turned on when using it for validation only. Interpret With. Allowing control functions is really powerful, and can be best understood where the dialect input to process is "generating" something (e.g xhtml). Its a great idea, it raises the standard for dialects that we implement. Now I know that you have made handling of control functions optional by allowing the the choice to use the Interpret term or not, but I wonder about security in the situation where some dialect input comes from a potentially un-trustworthy or unreliable source. [ repeat count 1000000...] could become an x-internet denial-of-service attack. :^) I'm sorry I don't have something more valuable or constructive to contribute to your great work! Thanks again for your efforts. Regards, Brett.

 [6/16] from: brett:codeconscious at: 15-Mar-2003 14:57


Hi Gabriele,
> I decided to release an alpha version of custom-types.r. You > can find it in:
<<quoted lines omitted: 3>>
> the patched actions in the global context with a * suffix (i.e. > PICK* etc.).
In an earlier example you showed: i: to complex! [0 1] which does not seem to work (I know the make method works) - just wondering if how To is to be used? Regards, Brett.

 [7/16] from: brett:codeconscious at: 15-Mar-2003 15:22


> In an earlier example you showed: > > i: to complex! [0 1] > > which does not seem to work (I know the make method works) - just
wondering
> if how To is to be used?
Looking further into the patched To function, I think this is something to do with type?* and the way it processes its parameter. A different question. Now that the patched actions are in Actions* and suffixed by * at the global level, what are good ways to write application code when taking advantage of custom types? E.g is this a good way? my-code-using-custom-types: [ v1: make complex! [x: 0 y: 1] v2: make complex! [x: 0.5 y: -1] result: add v1 v2 ] do bind my-code-using-custom-types in actions* 'self Regards, Brett.

 [8/16] from: g:santilli:tiscalinet:it at: 15-Mar-2003 9:49


Hi Brett, On Saturday, March 15, 2003, 4:57:05 AM, you wrote: BH> In an earlier example you showed: BH> i: to complex! [0 1] BH> which does not seem to work (I know the make method works) - just wondering BH> if how To is to be used? I decided to not patch the global native actions (this slows down REBOL noticeably, and would probably make custom-types.r not worth it). So you can write:
>> i: to* complex! [0 1] >> form* i
== "0 + 1i" or:
>> do bind [
[ i: to complex! [0 1] [ form i [ ] in actions* 'self == "0 + 1i" Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [9/16] from: g:santilli:tiscalinet:it at: 15-Mar-2003 9:51


Hi Brett, On Saturday, March 15, 2003, 5:22:34 AM, you wrote: BH> do bind my-code-using-custom-types in actions* 'self Yup. You can write something like: with-custom-types: func [code [block!]] [do bind code in actions* 'self] etc. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [10/16] from: brett:codeconscious at: 15-Mar-2003 22:05


I'm not sure what I've got wrong:
>> i: to* complex! [0 1]
** Script Error: complex! has no value ** Where: do-boot ** Near: i: to* complex! [0 1]
>> do bind [i: to complex! [0 1] form i] in actions* 'self
** Script Error: complex! has no value ** Where: do-boot ** Near: i: to complex! [0 1] form
>>
Regards, Brett.

 [11/16] from: g:santilli:tiscalinet:it at: 15-Mar-2003 14:10


Hi Brett, On Saturday, March 15, 2003, 12:05:31 PM, you wrote: BH> I'm not sure what I've got wrong: Did you run %complex.r ? :-) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [12/16] from: brett:codeconscious at: 16-Mar-2003 12:31


What versions of REBOL are compatible with custom-types.r? Where can I find the latest tfunc.r, subfunc.r files? Thanks, Brett.

 [13/16] from: g:santilli:tiscalinet:it at: 16-Mar-2003 11:00


Hi Brett, On Sunday, March 16, 2003, 2:31:21 AM, you wrote: BH> What versions of REBOL are compatible with custom-types.r? I only tested it with the latest versions; there could be issues about more aggressive evaluation in the earlier versions, if there's enough interested people I could check the code and use get-words where needed. BH> Where can I find the latest tfunc.r, subfunc.r files? http://www.rebolforces.com/~ladislav/tfunc.r http://www.rebolforces.com/~ladislav/subfunc.r Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [14/16] from: brett:codeconscious at: 17-Mar-2003 11:13


Hi Gabriele, Thanks I got it working for View 1.2.8. I re-downloaded the various files. Then I discovered the Halt at the end of the custom-types.r file which threw out my test script. It blows up on Core 2.5.5 though: Script: "Custom datatypes" (13-Mar-2003) Script: "Subfunc" (10-Mar-2003/10:57) Script: "Tfunc" (5-Mar-2003/18:04) ** Script Error: Invalid argument: native! ** Where: throw-on-error ** Near: func [ action [action! native!] dispatch [word!] name [word!] spec [block!] transp [logic!] ] [ Regards, Brett.

 [15/16] from: g:santilli:tiscalinet:it at: 17-Mar-2003 11:43


Hi Brett, On Monday, March 17, 2003, 1:13:58 AM, you wrote: BH> Then I discovered the Halt at the end of the custom-types.r file which threw BH> out my test script. Sorry, my fault, that was supposed to be debugging code. ;-) BH> ** Script Error: Invalid argument: native! That looks like a little bug in 2.5.5, NATIVE! is not defined...
>> action!
== action!
>> op!
== op!
>> native!
** Script Error: native! has no value ** Near: native!
>> type? :print
== native! Workaround: native!: type? :print I think you should submit it to feedback. :) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [16/16] from: brett:codeconscious at: 19-Mar-2003 10:18


Hi Gabriele,
> native!: type? :print
Thanks
> I think you should submit it to feedback. :)
Done. Regards, Brett

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