the utility of 'bind
[1/12] from: andreas::bolka::gmx::net at: 21-Jan-2004 18:41
I will spare you my thoughts about REBOL's contexts and 'bind (for
now) but I have a practical question:
What is the utility of 'bind? No, I don't necessarily mean the typical
cases where bind is needed to prevent errors. What I'm really thinking
about are situations, where REBOL's behaviour regarding contexts and
bind is actually contributing towards an elegant solution for a real
problem.
I think I remember various parse-based solutions posted to the list,
that utilized bind. This is basically a question to those who
understand _and_ use 'bind to actually solve problems: What do you use
it for? Do you think REBOL's behaviour in those regards is practical?
Are you aware of elegant solutions based on 'bind?
--
Best regards,
Andreas
[2/12] from: lmecir:mbox:vol:cz at: 21-Jan-2004 20:58
Andreas Bolka napsal(a):
>I will spare you my thoughts about REBOL's contexts and 'bind (for
>now) but I have a practical question:
<<quoted lines omitted: 8>>
>it for? Do you think REBOL's behaviour in those regards is practical?
>Are you aware of elegant solutions based on 'bind?
Hi Andreas,
BIND can be used to program e.g. a WITH function like with object [do
something]
I don't remember all cases where I used BIND. One case I recently
actualized was when I tried to circumvent the limitations of RETURN and
function attributes.
To describe the usage of BIND there: I defined (locally) the functions
called RETURN', THROW' and EXIT' having different behaviour, than their
native counterparts. Then I supposed, that a user would supply a code
block using the above words. I used BIND to give the meaning to the
words supplied from outside.
When I think about it now, I could do it without BIND using the USE
function only, but it would be less readable at least.
-Ladislav
[3/12] from: maximo:meteorstudios at: 21-Jan-2004 13:43
I used it in the glass ui dialect.
The easiest example was to contextualise action blocks to any face's actual object.
If bind is not used then the action block will be run as if it where in the global namespace.
This keeps you from using face/ all the time.
-MAx
---
You can either be part of the problem or part of the solution, but in the end, being
part of the problem is much more fun.
[4/12] from: tim:johnsons-web at: 21-Jan-2004 12:00
* Andreas Bolka <[andreas--bolka--gmx--net]> [040121 09:06]:
> I will spare you my thoughts about REBOL's contexts and 'bind (for
> now) but I have a practical question:
<<quoted lines omitted: 8>>
> it for? Do you think REBOL's behaviour in those regards is practical?
> Are you aware of elegant solutions based on 'bind?
Although there are python-esque ways of doing things and rebol-esque
ways of doing things, I find the two languages inform me of further
possibilites.
Every python object has a built-in method called __dict__ (as far
as I know).
If you pass to a python object a series of keywords, you can validate
such keywords against __dict__
A rough comparison would be a rebol subroutine like this:
__dict__: does[next first self]
and if one had an object method - called 'set for instance.
that looked like this:
set: func[arg[block!]][do bind arg 'self ]
a validation routine within the context could then test for
the previous existance of a word using self/__dict__
; untested code!
context.....[
validate: func[args[block!] /local keywords][
keywords: self/__dict__
foreach [arg value] args[
if not find keywords arg[
throw-an-error
]
]
]
]
and one could have an object-creation routine that would guarantee
that an object be created with certain builtin methods, such as those
above.
*****************************
* Who says rebol ain't OOP! *
*****************************
> that utilized bind. This is basically a question to those who
> understand _and_ use 'bind to actually solve problems: What do you use
Now, to put my money where my mouth is, I need to implement this!
tj
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com<
[5/12] from: nitsch-lists:netcologne at: 21-Jan-2004 22:04
Am Mittwoch 21 Januar 2004 18:41 schrieb Andreas Bolka:
> I will spare you my thoughts about REBOL's contexts and 'bind (for
> now) but I have a practical question:
<<quoted lines omitted: 8>>
> it for? Do you think REBOL's behaviour in those regards is practical?
> Are you aware of elegant solutions based on 'bind?
IMHO 'bind is a low-level tool.
Usually 'bind is used implicitely in 'func and [make object![]] and makes good
sense there.
sometimes one wants to add code later as if it was immediate there.
then 'bind makes some things possible.
for example, if one wants to add a function to an object later, which shall
use the objects wars implicitly.
a: context[ b: 1 c: 2 f: none]
a/f: func[][b + c]
does not work. uses global 'a and 'b.
a/f: func[] bind [b + c] in a 'self
works.
(often used to patch inbuild functions which are defined some context-levels
deep).
-Volker
[6/12] from: greggirwin:mindspring at: 21-Jan-2004 14:27
Hi Andreas,
AB> What is the utility of 'bind? No, I don't necessarily mean the typical
AB> cases where bind is needed to prevent errors. What I'm really thinking
AB> about are situations, where REBOL's behaviour regarding contexts and
AB> bind is actually contributing towards an elegant solution for a real
AB> problem.
Maarten uses it in Rugby in the creation of stubs for remote
invocation, but he would have to contrast how it might be done without
BIND as I haven't thought about it in detail.
I use bind in my FSM dialect. There, you define action blocks that are
triggered when the FSM is sent events. A single FSM can act like a
shared "engine", with BIND used to execute the actions in the proper
context--usually the one that sent the event, but could be any context
you want.
-- Gregg
[7/12] from: maximo:meteorstudios at: 21-Jan-2004 16:33
> --- Tim Johnson wrote: ---
> ; untested code!
<<quoted lines omitted: 8>>
> ]
> ]
another way to code the above (but this also support validating just one word):
context [
validate: func [word [block! word!] /local item][
either block! = type? word [
foreach item word [
if not (validate item) [return false]
]
return true
][
either found? in self word [true][false]
]
]
]
IMHO, I find this version a little bit more readable.
tim, this is not a challenge to your coding skills... I just like to show different views
of a problem, for academic purposes.... this helps novices a lot.
-Max
[8/12] from: tim:johnsons-web at: 21-Jan-2004 13:34
* Maxim Olivier-Adlhoch <[maximo--meteorstudios--com]> [040121 13:17]:
> > --- Tim Johnson wrote: ---
> > ; untested code!
<<quoted lines omitted: 23>>
> IMHO, I find this version a little bit more readable.
> tim, this is not a challenge to your coding skills...
:-) No problem.
See above. Untested code! Actually pseudo-code. I was just
translating how python would do it. And your method *is*
more rebol-esque (IMHO)
> I just like to
> show different views of a problem, for academic purposes.... this
> helps novices a lot.
And I find that seeing how different languages handle things
helps *me* alot. I wrote a 'first function for python that -
is more verbose than referencing by index but more clear...
especially when going from a language that references an
initial element as '1' to one that references an initial
element as '0'.
Permission to use your example?
thnx
tj
>
> -Max
>
> --
> To unsubscribe from this list, just send an email to
> [rebol-request--rebol--com] with unsubscribe as the subject.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com<
[9/12] from: maximo:meteorstudios at: 21-Jan-2004 19:12
> -----Original Message-----
> From: Tim Johnson [mailto:[tim--johnsons-web--com]]
<<quoted lines omitted: 7>>
> initial element as '1' to one that references an initial
> element as '0'.
funny, cause I too have some rebol mechanics ported to python...
One notable example is that I have implemented the 'select mechanism in python (although
0 based). And I use it often. I find its much easier to handle than poking around with
objects and classes for MANY situations. Plus I have less specifics to remember. If
everything uses lists, then there is less concern to remember all the commands in dict
and tuple datatypes (cause yess they are all individual and many little things are missing
in all of different series datatypes in python... This alone drives me crazy).
many don't see that rebol not only gives you its distinctive syntax, but also uses some
mechanics and an application design approach which is different than other languages.
there is something about the universal and consistent rebol way of thinking which makes
many other languages such a pain to learn (like python).
> Permission to use your example?
of course, use at will!!!
-MAx
[10/12] from: antonr:iinet:au at: 22-Jan-2004 12:38
> context [
> validate: func [word [block! word!] /local item][
> either block! = type? word [
either block? word [
is equivalent.
> -Max
Anton.<
[11/12] from: krobillard:cox at: 21-Jan-2004 20:30
You can use bind to execute functions in a protected context.
I have done this in a compiler for a game scripting language. I could have
implemented the compiler with parse, but then I could not make use of Rebol
constructs within my custom game dialect. By making the game commands normal
functions the capabilities of Rebol can be leveraged to expand macros and
templates, evaluate mathematical expressions, do conditional compilation,
etc.
In order not to pollute the global namespace, these game commands are placed
within a context, and to compile a block of code in that context requires
bind.
REBOL []
game-script-compiler: context [
commands: context [
; These emit bytecode.
run: func [speed] [print ["emit run" speed "here"] ]
jump: func [height] [print ["emit jump" height "here"] ]
laugh: does [print "emit laugh here"]
]
set 'compile func [code] [
do bind code in commands 'run
]
]
compile [
run 1.4
jump 2.0
laugh
run 1.4 * 0.8 ; Rebol will evaluate this for us as normal.
]
-Karl
On Wednesday 21 January 2004 09:41 am, Andreas Bolka wrote:
[12/12] from: tim::johnsons-web::com at: 22-Jan-2004 15:20
Python vs. Rebol (was the utility of 'bind)
* Maxim Olivier-Adlhoch <[maximo--meteorstudios--com]> [040121 15:41]:
> > -----Original Message-----
> > From: Tim Johnson [mailto:[tim--johnsons-web--com]]
<<quoted lines omitted: 16>>
> little things are missing in all of different series datatypes in
> python... This alone drives me crazy).
Let's see... On python I use HtmlGen, it's 2723 lines long
On python, I use 'ML. The version I'm using is 75 lines
or so.
Implementation on python is very finicky and much more time-consuming.
But I still use Python a lot because some clients require it, and
to make a long story short, it's more interoperable with perl. (and
definitely more readable) Fortunately, I charge by the hour :-).
> many don't see that rebol not only gives you its distinctive syntax,
> but also uses some mechanics and an application design approach which
> is different than other languages.
Without going into it and without encouraging argument, I
(and that's me now) feel that python does scale better. However, a
discliplined rebol programmer can exploit rebol's flexibilty to
that end too.
Example: rebol's 'out-of-the-box' subroutines automatically
creates global words (where in python they are automatically 'local')
BUT, I use a rebol 'def which automatically creates local words.
compliments of Andrew and Ladislav.
Solves that problem.
Anyway, I believe that I am preaching to the converted.
> there is something about the universal and consistent rebol way of
> thinking which makes many other languages such a pain to learn (like
> python).
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com<
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted