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

World: r3wp

[!REBOL3-OLD1]

Janko
3-Jun-2009
[15042x3]
yes, I know that this would not be anywhere near natively fast.. 
but do you think this would be theoretically possible?
I have to admit I don't know that much about continuations, just 
the surface stuff
do you need continuations to have coroutines?
BrianH
3-Jun-2009
[15045]
The generation of a continuation function would only be possible 
with system support, including internal state of natives. Without 
system support it would only be possible for continuations at the 
top level of a function's code (no nested blocks).
Janko
3-Jun-2009
[15046]
aha yes.. you are right.. inside a loop or other nesting this all 
breaks ..
BrianH
3-Jun-2009
[15047]
do you need continuations to have coroutines?

 It depends on the system - in some cases it is the other way around.
Steeve
3-Jun-2009
[15048]
funy: func [spec body][
	funco spec append copy [
		probe words-of stack/func 1 
		probe stack/args 1
	] body
]

>>foo: funy [x y z][x + y + z]
>>foo 1 2 3
[x y z]
[1 2 3]
BrianH
3-Jun-2009
[15049]
In theory you could have continuations in rebcode, using the pseudo-thread 
method.
Janko
3-Jun-2009
[15050]
something like coroutines or other ways to make cooperative multitasking 
would be really nice to have ... "real" threads / processes are just 
one side ot he concurrency IMHO
BrianH
3-Jun-2009
[15051]
Steeve, in theory that could work but I've been having trouble getting 
stack/func 1 to work - I think it's buggy.
Janko
3-Jun-2009
[15052]
cool Steeve, I was trying but didn't succeed at that
BrianH
3-Jun-2009
[15053]
Janko, you can have cooperative scheduling of real threads - all 
they have to do is cooperate, as long as a thread can pause.
Steeve
3-Jun-2009
[15054x2]
in fact stack/func is useless, because u can use the variable spec 
to get parameters
same result with:

funy: func [spec body][
	funco spec append compose/deep [
		probe [(spec)]
		probe stack/args 1
	] body
]
BrianH
3-Jun-2009
[15056]
Only if you know which function you are calling from. I figured out 
the stack/func 1 bug.
Janko
3-Jun-2009
[15057]
but isn't the main difference that coroutines can be made very light 
.. you can have 1000s of them, and with threads creatin of them and 
mem. is more expensive?
BrianH
3-Jun-2009
[15058]
Only if the system is designed to support them. If not, then they 
are slower.
Janko
3-Jun-2009
[15059x3]
Erlang and stackless python which can create >100.000 "processes" 
surelly does not use uses native threads for this ... I imagine it 
has M(green processes) / N (OS processes)
(Erlang that is ... stackles py I think uses just green threads)
by system you mean the rebol runtime in our case or the OS?
BrianH
3-Jun-2009
[15062]
The REBOL runtime.
Janko
3-Jun-2009
[15063]
aha, yes that I agree fully .. that's why I was hoping the makers 
would think about some form of lighter runtime threads/processes 
whatever they are :)
Maxim
3-Jun-2009
[15064]
here is an example of how we could use the unit system if it where 
implemented.


ANY unit moniker could be used, and in fact the switch tables below, 
could be context-specific and dialect-configured, adding to the DSL 
power of  REBOL... 


ex: dm could be decimeter or deutchmark (the later should be DM anyways, 
no?) , based on context, the convertion units could mean either or... 
with a default convertion table explicitely defined.

a simple func could let us append or change the conversion tables 
used throughout the system.  


Imagine if the VID would use units directly.  you set your locale 
(or get it from OS) and see values as they should be for your locality.


unit-convert: func [
	in "unit value to convert"
	to-moniker "to what unit type to you want to convert to"
][
	; note: incompatible types set 'IN to value none
	in/value: switch to-moniker any [
		switch in/moniker [
			{mm} [
				[
					{m} [in / 1000]
					{dm} [in / 100]
					{cm} [ in / 10]
					{'} [in * 0.0032808399]
					{"} [in  * 0.0393700787]
				]
			]
			{"} [
				[
					{m} [ in * 0.0254]
				]
			]
		]
		; empty result set, switch on nothing
		[]
	]
	in/moniker: to-moniker
]


unit-convert 100mm "m"
== 0.1m

unit-convert 100" "m"
== 2.54m

unit-convert 2mm  {'}
== 0.0787401575'
BrianH
3-Jun-2009
[15065]
Change /moniker to /unit.
Maxim
3-Jun-2009
[15066]
just a label...  now find the more powerfull idea I added here  not 
readily obvious... but you should get it....  ;-)
BrianH
3-Jun-2009
[15067]
It still wouldn't replace money!, because the international standard 
syntax for specifying money uses a prefix, not a suffix.
Maxim
3-Jun-2009
[15068x2]
notice the inch handling ?
;-)
Steeve
3-Jun-2009
[15070x3]
it would, if instead of switch functions we'll use parse
it's the same idea, of having computed/values (with accessors)
But Carl don't like the idea
Maxim
3-Jun-2009
[15073x3]
no steeve, at that level, its the rebol lexical analyser.
we can't just but-in parser rules.  its a core level of the interpreter.
you can just use load/next in a parser rule... I've done it often 
and it works.
Steeve
3-Jun-2009
[15076x2]
it has nothing to do with the lexical analyser, we just need a new 
data type, to construct computed variables
internally, those variables would be sort of objects with methods
Maxim
3-Jun-2009
[15078]
but I would like a way to get invalid tokens loaded as invalid values... 
that way I'd use block parsing .  so far, I've been using string 
parsing about 90% of the time.  its a shame, since I'm loading stuff 
much more slowly than rebol could let me do it using its native loading.
Steeve
3-Jun-2009
[15079]
but behaving like regular variables
Maxim
3-Jun-2009
[15080x2]
we are talking about representing the lexical form of unit-like values 
here steeve, not the custom datatypes.
all OOP with accessors do exactly what you want.
Steeve
3-Jun-2009
[15082x2]
i'ts the same thing, you just need a specific method (ie. dispalyed-as) 
for the computed vars
yes i can do it with OOP, but i don't want to have to code stupid 
things like my-var/set, my-var/get
BrianH
3-Jun-2009
[15084]
But Carl don't like the idea

 - as I recall, changes in object semantics have been put off until 
 later, not permanently.
Maxim
3-Jun-2009
[15085x3]
 those variables would be sort of objects with methods

  that is exactly WHAT an accessor-enabled variable IS  , also known 
  as a datatype   ;-)
the accessors are just events... you have to know WHEN and WHAT to 
do with a variable...   It would be fun if generic objects allowed 
us to set accessors per instance, just like python allows it, but 
alas, Carl doesn't realise just how often this could be used to simply 
a vast array of code.
simply = simplify
BrianH
3-Jun-2009
[15088]
(repeating myself) As I recall, changes in object semantics have 
been put off until later, not permanently.
Steeve
3-Jun-2009
[15089]
i don't ask a new semantic for objects (with obvious drawbacks)
i ask for a new datatype, let the objects like they are
BrianH
3-Jun-2009
[15090]
All bound words are object fields or function context fields, so 
that is exactly what you are asking for.
Steeve
3-Jun-2009
[15091]
yep so do it now :-)