World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Henrik 10-Mar-2005 [42] | thanks for the suggestions :-) I'm doing it differently now though... |
Anton 10-Mar-2005 [43] | The most elegant solution would be to patch layout so it accepts set-paths. |
Normand 12-Apr-2005 [44] | Speaking of double bind, I have no clue of the how-to to this clue. In Ocaml we can make co-recursive definitions, also with negation. But when I try this on Rebol, it claims the value before I have the time to define it: a: not b and b: not a. Interp: ** script error, b has no value. What is the method ? Or are we out of paradise? I could use that as a form of loop, or a form of lexical closure to model some linguistic phenomenas. But how? We know the problems of complement of complement, but as a function value it should be feasible. |
JaimeVargas 12-Apr-2005 [45x2] | Do you have an example, besides: a: not b b: not a |
In rebol this are executed serially, so the first statement fails because b is not defined. | |
Normand 12-Apr-2005 [47] | A pair number cant be defined without impair. pair is impair +1 and impair is pair +1. So we have to define both at the same time. In logic, the negation is a function where true is false and false is true. Not and complement are native to rebol. If I try a: not 'b b: not ''a. asking the value of a, :a, does not return not b but false. Something like this does not seem to work. What I want is criss-crossed functions one defined by the other. In principle, Rebol being functionnal. It should be simple, a one liner, but I am too newbee to find the elegant way to do this. |
Ammon 12-Apr-2005 [48] | Normand, can you give us the actual code that is tripping you up here? Perhaps with a look I could help you out... |
Volker 12-Apr-2005 [49] | Normand, seems you do not define functions, but executes the expressions directly? pair: func[][impair + 1] impair: func[][pair + 1] the code makes no sense but rebol accepts it perfectly. |
Ladislav 12-Apr-2005 [50x2] | Normand: don't you mean this?: odd?: func [i] [either i = 0 [false] [even? i - 1]] even?: func [i] [either i = 0 [true] [odd? i - 1]] odd? 11 |
warning: odd? and even? are already defined in Rebol, you might prefer to use names like pair? and impair? instead like you wrote above | |
Normand 28-Apr-2005 [52x4] | Thanks for the answer. I am aiming in the direction of corecursive types, to model a category thing. So the following works. |
Co-recursive types: >> owed: func [x] [either paid? x [negate x][false]] >> owed?: func [x] [either all [integer? x negative? x] [true] [false]] >> paid: func [x] [either owed? x [negate x] [false]] >> paid?: func [x] [either all [integer? x positive? x] [true] [false]] >> a: 5 == 5 >> owed a == -5 >> owed? a == false >> owed? b: owed 5 == true >> a: paid b == 5 >> paid? a == true >> paid? paid -5 | |
Now I need custom types. | |
--Type inference from a newbee point of view: What if I wanted to form true (but un-native) datatypes ? To program them, I shall use the same method as other types in Rebol: To mention the type as its value : seasoning!: seasoning!, like the definition of the type money!: 'money. Rather, I would like to do type inference as they do, for example in ML (I adapt the example from Felleisen's LittleMLer): So I would need to define a new type and verify the type of a word with type? seasoning!: ('salt or 'pepper) Unfortunately this does not seems possible ** Script Error: Cannot use or~ on word! value ** Near: 'salt or 'pepper In Rebol: >> source integer! integer!: integer! type? 1 == integer! but natural!: (0 or natural +1) Type inference: seasoning? salt Would like the answer == seasoning is-of-type? 'salt seasoning Would like the answer == true Am I forced to turn to Ocaml to do this? I am stuck. Thanks for any help! | |
Ladislav 28-Apr-2005 [56] | I don't know exactly what you can accept and what not, but this will work: seasonings: [salt pepper] seasoning?: func [value [any-type!]] [found? find/only seasonings get/any 'value] seasoning? 'salt |
Sunanda 28-Apr-2005 [57] | As far as I know it is not possible to define new types. Not sure that would solve your problem anyway. A word can point to a value that has only *one* type (ignoring the heirarchy -- eg block! is also series!). So complex assertions about something would not be easy. Maybe rethink the need.....Use objects to hold both a value and a type: >> item: make object! [value: 'salt type: 'seasoning] >> item/type == seasoning >> 'seasoning = item/type == true You could encapsulate that in a couple of functions and expand the scope (maybe make type a block with multiple values) |
Anton 28-Apr-2005 [58x8] | Gabriele Santilli has made some custom types. I don't remember having fully understood how it works, so I can't tell you how he did it ! But it can be found here: http://www.colellachiara.com/soft/YourValues/libs/ |
custom-types.r is GPL. | |
(It's really very clever. :) | |
Just reading the code... Needs a demo. custom-types.r needs standard-actions.r | |
I'll try to make one. | |
Hmm, there seems no easy way to make a demo. Gabriele is using an include mechanism (prebol.r I think) from the SDK . But it looks like http://www.colellachiara.com/soft/YourValues/main.r is the starting point. | |
Gabriele, if you're listening, the header of http://www.colellachiara.com/soft/YourValues/yourvalues.r contains: File: %main.r ; <-- should be %yourvalues.r ?? | |
Gosh, it's too hard for me to do in any reasonable time. I suggest looking at the code to figure out the method used, then see if you can make your own custom types. | |
Gabriele 28-Apr-2005 [66x5] | Anton: the header is wrong because that file is generated with prebol using main.r |
(a version of prebol with some minor modifications.) | |
about an example: there should be a complex.r in that dir that is a bit outdated (lacks support for molding and loading) but should be a good start. also template.txt is the starting point to create a new type. | |
you need to use starred actions on them though, i.e. add* instead of add, insert* instead of insert and so on, as well as make* and to*. | |
maybe somedaye i'll have the time to finish this stuff and add docs... | |
Anton 28-Apr-2005 [71] | :) Now I think I remember I asked you that about the File: before sometime... |
Gabriele 28-Apr-2005 [72] | but, i'm not 100% sure Normand really needs this. custom types are not always the most elegant solution; actually, they are very rarely. |
Anton 28-Apr-2005 [73] | What are you up to these days anyway ? |
Gabriele 28-Apr-2005 [74x2] | also, i would really discourage a newbie from using that stuff as it is very experimental :-) |
finishing the detective version 3, then (don't know if i can say that, so i won't.) | |
Anton 28-Apr-2005 [76x3] | Why not ? :) |
I wish I had some understanding of inference rules. Never studied Lisp stuff. | |
I think all those parens scared me away. | |
Gabriele 28-Apr-2005 [79] | i don't think common lisp does any type inferencing. |
Anton 28-Apr-2005 [80] | That's how much I know. :) |
Gabriele 28-Apr-2005 [81x3] | and, i think an interpreted language would probably have a hard time at it, except for simple cases like the seasoning above. |
which is elegantly solved as ladislav pointed out anyway. | |
the only advantage of having a real type in that case is type checking in fuction arguments; you don't get that with my custom-types (i don't think it is worth redefining FUNC etc. just for this), and it's not a big deal actually. | |
Anton 28-Apr-2005 [84] | Are you actually using the custom types in any apps ? |
Gabriele 28-Apr-2005 [85x2] | i'm using something close (i.e. a very dumbed down and specialized version of it) in the backend for the portals for the Detective |
basically the scripts interface to the mysql db via custom rebol values | |
Anton 28-Apr-2005 [87x3] | I see. |
I've just noticed a new global word PATH existing since View 1.2.10, an undocumented function. | |
--> rambo | |
Volker 28-Apr-2005 [90] | About custom types: thats objects. they work like dynamic OO, no static typing and inferencing like ML |
Normand 30-Apr-2005 [91] | Thanks for all those suggestions. I was out for quite a while and am very happy of all those remarks. It will help orient my trials&errs. About objects, dynamic versus static, If I understand it, in Rebol it is static? I never had to use them except to encapsulate the whole of an app. Is there a trick to mimick something dynamic to hold changing values? Maybee a copied block is enough? I wonder because I regularly try to add code to a bibliographic database, a kind of a variation on bibtex (never ended, allways in progress), And I am not too far from aiming the storage mechanism and wonder what I should use to hold something like from 5 to 10 thousand references (my actual need is 3.5K) I used endnotes in the past, but dreamed about my own. It is a lot of work (more than I expected as it is my first app). Up to now I think I will use simply name-value pairs, like Carl's cardex. This kind of data is more like a ragged array, the fields and their numbers allways vary, and I may amend their list with time. The idea of using an object would be nice but need something where I may add or retract variable names and change their values. By the way, I thank Volker for his edit-tools, that may help to add a writing pad. And his double slider is refreshingly new for such and old paradigm as an editor. |
older newer | first last |