r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Anton
21-Sep-2006
[5370]
You shouldn't have to do that (load mold). Can we see a bit more 
of your code ?
Henrik
21-Sep-2006
[5371x2]
rel-obj: make object! []

add-relation: func [path-block [block!] /local p v w] [
  p: to-block 'rel-obj
  parse path-block [
    any [
      [set w word! (
        unless all [

          find either object? do to-path p [first do to-path p][[]] w
          insert tail p w
        ] [

          do load mold reduce [to set-path! p make do to-path p reduce [to-set-word 
          w none]]
        ]
      ]
   ]
]

I'm not sure it's enough...
it's only a small part of the function
Anton
21-Sep-2006
[5373x2]
usage example of add-relation ?
eg..  add-relation [...]   <-- what's in the block.
And what's the result supposed to be ?
Henrik
21-Sep-2006
[5375]
I'm rewriting my relations engine, if you remember that one.


I need to traverse rel-obj via paths, so I store the path as words 
in a block. This is in order to maintain the current position in 
a deep object.


The input can be any arbitrary path of words and values. If the values 
or words don't exist, they will be created on the fly. That's what 
I use 'p for.
Anton
21-Sep-2006
[5376]
Ah I see.
Henrik
21-Sep-2006
[5377]
the code with the do load mold... is supposed to insert a new object 
at the path position if the current value at that point is 'none. 
I removed some of that "if none?" logic for clarity.
Anton
21-Sep-2006
[5378]
So rel-obj can start out completely empty, but fill with values afterwards 
?
Henrik
21-Sep-2006
[5379x2]
yes. an example could be if rel-obj was empty:

add-relation [users male "Joe"]
add-relation [users female "Jenny"]

later on, when you look it up, it's supposed to look like:

get-relation [users]
== [male female]
get-relation [users male]
== ["Joe"]

You can go deep:

add-relation [users male "Joe" age-group "Senior"]

And you can do reverse relations:

add-relation [age-group "Senior" users "Joe"]
the rules and structure is completely arbitrary, which is one of 
the stronger points of the relations engine.

however the current version forces you to use a path block structure 
of [word value word value word value...] which forces you to choose 
a value that will not be used for branches where only one path should 
exist. that's why I'm doing a rewrite.
Anton
21-Sep-2006
[5381]
I suspect you are assuming you can extend objects, which cannot be 
done in rebol currently.
Henrik
21-Sep-2006
[5382x2]
the relations engine already does that :-)
but I need some more freedom in the path block
Anton
21-Sep-2006
[5384x2]
No, I mean extending objects and keeping the same object.
>> a: make object! []
>> b: make a [new: none]
>> same? a b
== false
Henrik
21-Sep-2006
[5386]
yes, but that problem was solved long ago.
Anton
21-Sep-2006
[5387]
ok.
Henrik
21-Sep-2006
[5388]
I simply re-make the object with itself plus the new branch inside 
rel-obj. works fine, but there's some stuff to manage.
Anton
21-Sep-2006
[5389]
I think you might have found a bug. I see something which I find 
hard to explain:
Henrik
21-Sep-2006
[5390x2]
oh?
well, I have to go to bed now, so good luck with the bug hunting 
:-)
Anton
21-Sep-2006
[5392x2]
>> obj: none
== none
>> path: [obj]
== [obj]
>> code: reduce [to-set-path path 'make to-path path [new: 123]]
== [obj: make obj [new: 123]]
>> print code/1/1 = 'obj
true
>> ?? code
code: [obj: make obj [new: 123]]
== [obj: make obj [new: 123]]
>> do code
== none ; <-- what a strange result !
>> ?? obj
obj: none
Same here. Sleepies :)
Gabriele
21-Sep-2006
[5394x2]
a path with only one element is probably not supported.
(btw, you're doing make none [new: 123] so obviously you get none, 
Anton :)
Henrik
22-Sep-2006
[5396]
isn't a path with one element pretty useless then? I just wish that 
set would work on paths. it makes sense to me.
Ingo
22-Sep-2006
[5397]
+1 for set on paths!
Gabriele
22-Sep-2006
[5398]
a path with one element is useless indeed. you cannot create it normally; 
it's like words with a space, or issues with a space, and so on. 
they exist, but they are not "valid" in a strict sense.
Anton
23-Sep-2006
[5399x2]
%/C/
Pretty useless directory path - it's only got one element.
Gabriele, oops about the none.
Henrik
23-Sep-2006
[5401]
I see the problem.  A path can represent different things, so if 
your path is not representing anything yet, then REBOL won't know 
how to deal with it as opposed to setting a word with 'set.
Anton
23-Sep-2006
[5402x5]
No, wait a minute, this code is what I meant (just changes the first 
line):
obj: make object! []
path: [obj]
code: reduce [to-set-path path 'make to-path path [new: 123]]
print code/1/1 = 'obj
?? code
do code
?? obj
OBJ seems not to have been changed by doing the code.

Gabriele has seen that a set-path! with only one element doesn't 
work, but you can use a set-word! instead, because they're conceptually 
the same, and they look the same:
>> to-set-path path
== obj:
>> to-set-word path/1
== obj:
So this seems to work:

 code: reduce [either 1 = length? path [to-set-word pick path 1][to-set-path 
 path] 'make to-path path [new: 123]]
Hmm.. I think I agree with Gabriele - the path with one element molds 
just like a word, so it would not load back correctly. Mold/all could 
be made to handle 1-element paths specially, writing the datatype 
eg:  #[path! [obj]]  Is it worth it, though ?
Henrik
23-Sep-2006
[5407x4]
well, it does seem to work, but it's only the first step of a few 
more. I hope it'll be worth it :-)
no, actually it doesn't work. I may be attacking the wrong problem. 
whenever I need to use the set-path part of your code, it, just like 
before, doesn't work.
the to-set-path part, sorry
so it's not a one-element-path problem but a "simple" issue of binding 
the path to the right context.
Volker
23-Sep-2006
[5411x2]
BTW you can manipulate a path like a block. And it may help to use 
'in.
But still ugly.
Anton
23-Sep-2006
[5413]
Henrik, what would rel-obj look like after issuing this ?
	add-relation [users male "Joe" age-group "Senior"]
Henrik
23-Sep-2006
[5414]
make object! [
	users: make object! [
		male: [
			"Joe"
			make object! [
				age-group: ["Senior"]
			]
		]
	]
]
Gregg
23-Sep-2006
[5415x2]
%/C/ actually has more than one element. %/ only has one element, 
in the file sense, but it also has a special meaning. A path with 
one element is just a value, most likely a word.
That said, I don't think they would be entirely useless, but the 
need for them seems very small.
BrianH
23-Sep-2006
[5417]
%/C/ is a file! not a path!
A file! is a string type.
Gabriele
24-Sep-2006
[5418]
the first element of a path! must be a word! (i'm not aware of any 
other ways to build a path, except for using make path! directly), 
and there must be a second element.
Anton
24-Sep-2006
[5419]
:) I understand Brian, it was just my first retort. :) Of course, 
a 1-element path! would be indistinguishable from a word!