World: r3wp
[View] discuss view related issues
older newer | first last |
Anton 6-Oct-2006 [5684] | I didn't mean to stress "using FUNC", just pointing out that we are using FUNC in this case. |
Pekr 6-Oct-2006 [5685] | ok, thanks a lot .... for me the interesting part was 'head ... |
Anton 6-Oct-2006 [5686] | Of course you can check each step using PROBE. |
Pekr 6-Oct-2006 [5687x2] | because .... copy/deep still returns block ... I thought the position does not matter |
I know .... | |
Anton 6-Oct-2006 [5689] | It's only because INSERT returns the block at the position *after* the newly inserted part that we need HEAD. |
Pekr 6-Oct-2006 [5690x2] | I know - but I thought that func simply accepts the block, regardless of position .... |
I thought ti would work without the head, but it does not ... | |
Anton 6-Oct-2006 [5692] | Well, most functions care about the series index. We can easily test if FUNC does: >> body: tail [print "hello"] == [] >> f: func [] body >> f <---- nothing is printed |
Pekr 6-Oct-2006 [5693] | it is imo bug :-) |
Anton 6-Oct-2006 [5694] | Nah... |
Pekr 6-Oct-2006 [5695] | func accepts the second argument as a block ... not a block at certain position :-) it should automatically move to the head, but ... maybe not ... |
Ladislav 6-Oct-2006 [5696] | no way, it would be bug if it worked differently |
Anton 6-Oct-2006 [5697x2] | Blocks are series and series are fundamental to understanding rebol. You must understand this behaviour and be comfortable with it, because understanding it opens up a lot of the power of series. |
Here's a different way, which puts the new code in the key handler part: view layout [ field feel [ use [body blk][ body: copy/deep second :engage blk: next find select body [switch act][key] change/only blk compose/only [if event/key <> #"^M" (blk/1)] ?? body engage: func [face act event] body ] ] ] | |
Pekr 6-Oct-2006 [5699x2] | Ladislav - I do understand it from the series pov ... the code is surely ok .... but from the func specs, I am not so sure: |
body -- The body block of the function (Type: block) | |
Anton 6-Oct-2006 [5701] | You probably don't spend enough time playing with function creation :) |
Pekr 6-Oct-2006 [5702x2] | I would expect pointer to the block, not to some concrete position inside that block |
I don't, never :-) | |
Anton 6-Oct-2006 [5704x3] | Here's the "copy, paste and bind" way: |
view layout [ field feel [ engage: func [face act event] bind bind [ switch act [ down [ either equal? face focal-face [unlight-text] [focus/no-show face] caret: offset-to-caret face event/offset show face ] over [ if not-equal? caret offset-to-caret face event/offset [ if not highlight-start [highlight-start: caret] highlight-end: caret: offset-to-caret face event/offset show face ] ] key [if event/key <> #"^M" [edit-text face event get in face 'action]] ] ] system/view ctx-text ] ] | |
Notice we are binding the code first to system/view, then to ctx-text. (Then it is also bound to the function context.) | |
Pekr 6-Oct-2006 [5707] | why is there a difference? >> body: [print "hello"] == [print "hello"] >> f: func [] body >> same? body second :f == false >> probe second :f [print "hello"] == [print "hello"] |
Anton 6-Oct-2006 [5708x2] | Obviously FUNC copies the body block. |
Why is that good ? Probably because that's what people expect most of the time. | |
Pekr 6-Oct-2006 [5710x2] | ah, ok, thanks |
to your double bind example - what does it do internally? you first bind the block to system/View - what happens in that context, and what happens in next context - ctx-text? | |
Anton 6-Oct-2006 [5712x2] | When you bind a block, eg: bind [all my words] some-context an attempt is made to bind each of the words in the block to the specified context. If the context contains the word in question, then the word is bound, otherwise the word is left with the same binding as it had before. |
So if I bind [caret: "hello"] system/view then the first word in the block gets the same context as this word: in system/view 'caret and thus it also references the same value, because it is the context which determines what value a word has. | |
Pekr 6-Oct-2006 [5714x2] | what does it mean the word it bound? it is registered somewhere at memory, in some word table, as belonging to that new context, or it just is assigned particular value of tha word in the context we are binding it to? |
now I seem to understand, just did some small example myself: block: [print a] do block ; 'a is not known my-context: context [a: 1] do bind block my-context ; now 1 is printed | |
Anton 6-Oct-2006 [5716] | And note that it works also for sub-blocks: do bind [print [a]] context [a: 1] |
Pekr 6-Oct-2006 [5717] | I don't use bind, as it is more guru stuff, but is the bind as it is sufficient for you? e.g. wouldn't you prefer bind not binding for sub-blocks by default, and e.g. having bind/deep for such thing? |
Anton 6-Oct-2006 [5718] | Yes, I would prefer more options for binding particular parts of a block "surgically". |
Pekr 6-Oct-2006 [5719] | hehe, I can rebind whatever, even functions? do bind [print a] context [a: 1 print: :probe] |
Ladislav 6-Oct-2006 [5720] | yes, you can |
Pekr 6-Oct-2006 [5721] | hmm, but maybe mine is not example of binding anyway, it just simply created alias, no? |
Ladislav 6-Oct-2006 [5722] | I would prefer more options for binding particular parts of a block surgically"" - that is possible e.g. using my BUILD dialect or other instruments... |
Anton 6-Oct-2006 [5723x2] | It *is* an example. |
That's true, Ladislav, I was just about to write that it is possible to write higher-level functions. | |
Pekr 6-Oct-2006 [5725] | yes, it seems so ... print: :probe is known only in a newly created context, or so it seems ... |
Ladislav 6-Oct-2006 [5726] | right, Pekr |
Pekr 6-Oct-2006 [5727] | 'bind offers whole level of interesting low level (or high level, it depends how you look at it :-) magic ... |
Ladislav 6-Oct-2006 [5728] | right again |
Pekr 6-Oct-2006 [5729] | you can "borrow" your values here or there ... |
Ladislav 6-Oct-2006 [5730x2] | actually, you "borrow" variables, when using BIND |
(which is almost the same in many cases) | |
Pekr 6-Oct-2006 [5732] | and when such variable "points to" some other context, you get there too with newly binded word? Well, that is interesting also from security pov - we have powerfull instrument on one hand, but we have to be carefull on the other hand ... |
Ladislav 6-Oct-2006 [5733] | yes, that is why REBOL modules are hard to implement |
older newer | first last |