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

World: r3wp

[Core] Discuss core issues

BrianH
16-Nov-2009
[15020]
Give me a sec, I'll list out the relevant functions...
Maxim
16-Nov-2009
[15021x2]
hehe, yeah.... doh!  ;-)
(above related to tuple position comment)
BrianH
16-Nov-2009
[15023]
Position: HEAD, TAIL, HEAD?, TAIL?, AT, SKIP, NEXT, BACK

Contents: PICK, POKE (for modifiable series), ordinals (FIRST, ..., 
LAST)

Sequence: PICK and POKE can use numbers (used to implement ordinals)

Persistent position and sequence: All of the above are repeatable, 
with no position change side effect.
Maxim
16-Nov-2009
[15024]
and INDEX?   ;-)
BrianH
16-Nov-2009
[15025x4]
Right, as a position function.
LENGTH? too. Note that in R3 an image! counts as a series, though 
it has 2 different position measures.
Bitsets, tuples, objects and maps don't have position. Objects and 
maps don't have sequence either (at least not in theory).
Ports in R3 (or open/direct or command ports in R2) don't have persistent 
position and sequence, or reference position. This makes them streams, 
not series.
Maxim
16-Nov-2009
[15029]
yes basically, they are always at position 0 and looking at the data, 
implies you remove it, so ports are like quantum series  ;-)
BrianH
16-Nov-2009
[15030]
The reference position vs inherent position distinction is important. 
That is why the position functions are seeking procedures for ports, 
while they are pure reference-returning functions for series.
Chris
16-Nov-2009
[15031x2]
It'd still be nice to have an interface that in some ways behaved 
like R2 ports (I think of it as adapter!) that allow the above series 
functions to operate on customised, abstracted series.  Perhaps I'm 
overlooking a simpler way of addressing the problems I have in mind.
It seems (by my reading) R3 ports have evolved toward more closely 
modelling streams of data as opposed to pools.
Henrik
17-Nov-2009
[15033]
BrianH, I don't understand your get-path example. How can I use it 
to build more paths? You have to remember that I'm not interested 
in having a default path which then is altered. I want to build then 
by joining several paths together, just like file! does.
BrianH
17-Nov-2009
[15034x2]
Well, paths are like blocks, not like filenames. You can't make them 
act like filenames without breaking them *in every other way*. You 
can build path just fine with JOIN and APPEND, you can fully evaluate 
them with DO, and you can partially evaluate them with get-paths 
without ever needing to use GET IN. Functionally, there is no problem 
with R3's current behavior except bugs 396, 861, 1236, 1339, and 
maybe 746 and 803.
We can safely assume that you are talking about R3 when proposing 
that behavior be changed, since R2 is in compatibility mode.
james_nak
18-Nov-2009
[15036]
Anyone know a simple way to transform a block of sub-blocks into 
a single block while retaining the original type? I have [ [1] [2] 
[3]] and I'd like [ 1 2 3]. I can do with with form and parse but 
it  then I get ["1" "2" "3"].
kcollins
18-Nov-2009
[15037]
result: copy [] foreach x [[1 2]] [3 4] [5 6]] [append result x]
Geomol
18-Nov-2009
[15038x4]
>> blk: [[1][2][3]]
>> forall blk [change blk blk/1]
>> blk
== [1 2 3]
My version can only copy with subblocks of length 1.
copy = cope
Maybe better:
forall blk [change/part blk blk/1 1]
Izkata
18-Nov-2009
[15042]
Slight differences - no internal blocks are preserved in Geomol's:
>> blk: [1 [2] [3 [4]] [5 6]]    
== [1 [2] [3 [4]] [5 6]]
>> forall blk [change/part blk blk/1 1]                     
== []
>> blk
== [1 2 3 4 5 6]


My version (gives the same result as kcollins, but is in-place like 
Geomol's) only flattens one level:
>> blk: [1 [2] [3 [4]] [5 6]]          
== [1 [2] [3 [4]] [5 6]]
>> forall blk [blk: back insert blk also blk/1 remove blk]
== [6]
>> blk
== [1 2 3 [4] 5 6]
Graham
18-Nov-2009
[15043]
>> to-block form [ [ 1 [ 2] 3 ] [ 4] ]
== [1 2 3 4]
Chris
19-Nov-2009
[15044]
Another, from the 'parse school:

	parse block [
		any [block: any-block! (insert block take block) :block | skip]
	] head block
Maxim
19-Nov-2009
[15045]
this should be a native in R3... there are MANY places where this 
is both needed and its always slow.
Graham
20-Nov-2009
[15046x2]
I've got some gui code which I am loading from a text string, and 
then running it.  I am binding it to some local words which I want 
to use and that works fine.

But I also want to invoke functions in the global context and it 
can't find them.  What to do?
eg. the text is

button "test" [ alert "hello" ]

and I get an error clicking on the button.
Chris
20-Nov-2009
[15048]
Bind the loaded text to a global word first ('system ?) then to your 
local context.
Graham
20-Nov-2009
[15049]
So, here, how would I get this working?


test: func [ /local lo ][ lo:  {button "test" [ alert "hello" ]} 
view layout to-block lo ]
Chris
20-Nov-2009
[15050]
test: func [ /local lo ][ lo:  {button "test" [ alert "hello" ]} 
view layout bind to-block lo 'all]
Graham
20-Nov-2009
[15051]
Let me try that ...
Chris
20-Nov-2009
[15052]
Just don't use 'all in your local context.
Graham
20-Nov-2009
[15053]
currently I am binding the block to some local words in the context
Chris
20-Nov-2009
[15054]
Bind to 'all first, then your local word(s)
Graham
20-Nov-2009
[15055x2]
eg ...
this is user written gui code which is why I bind to the local context 
to prevent them doing stuff that I think might be dangerous.  But 
I want to allow some exceptions.
Chris
20-Nov-2009
[15057]
Assign the global functions to local words:

context compose [alert: (:alert)]
Graham
20-Nov-2009
[15058x2]
this doesn't work ...


 test: func [ /local lo alert] compose/deep [alert: (:alert) dummy: 
 none lo:  {button "test" [ alert "hello" ]} view layout bind to-block 
 lo 'dummy]
dummy should be local too
Chris
20-Nov-2009
[15060]
Yeah, not sure why - do you get "alert has no value" ?
Graham
20-Nov-2009
[15061]
** Script Error: alert word has no context
** Where: func [face value][alert "hello"]
** Near: alert "hello"
Chris
20-Nov-2009
[15062x2]
do-protected: use [alert][
	alert: get in system/words 'alert
	func [txt][do bind to-block txt 'alert]
]

do-protected {alert "Foo"}
do-protected {print "Foo"}
So in theory it works, next how to apply to your function.
Graham
20-Nov-2009
[15064x3]
Not working in my function yet.
this works 


test: func [ /local lo alert dummy] compose/deep [alert: get in system/words 
'alert dummy: none lo:  {button "test" [ alert "hello" ]}    view 
layout bind to-block lo 'dummy ]

just not working in my script though
oh .. remove the compose/deep
Chris
20-Nov-2009
[15067x3]
Hmm, try this:
isolate: func [words [block!]][
	use words compose/only [
		set (copy words) forall words [change/only words get words/1]
		first (copy words)
	]
]


do-protected: func [txt allowed][do bind to-block txt isolate allowed]
do-protected {print "foo"} [print]
do-protected {alert "foo"} [print]