Jens wrote:
And yes, everything will be incredibly clever, of course!
I forget who said this, some software engineering guru, but since it's harder to debug code than to write it in the first place, if you write code as cleverly as you can, then you can't debug it!
So, you mean, everything will be incredibly standard and built out of off-the-shelf components whenever possible, right?
Offline
I never noticed that setting a variable equal to a list in BYOB 3 isn't a one-time action, all changes that are made in the list are then reflected in the variable from that point forward. Is there someway to prevent this behavior?
EDIT: I thought "Copy of" would do the trick, but I suppose I was wrong.
Last edited by shadow_7283 (2012-10-01 21:39:57)
Offline
shadow_7283 wrote:
Is there someway to prevent this behavior?
EDIT: I thought "Copy of" would do the trick, but I suppose I was wrong.
"Copy of" will do it unless you have a list of lists; "Copy of" does only a toplevel copy, so sublists are still identical in the two versions. You can write your own "Deep copy of" that recursively copies sublists.
I'm a little surprised that you want a deep copy, though; that's unusual.
PS It's not that the variable changes when you change the list. The value of the variable is a pointer to the list; that pointer remains constant even as the contents of the list change. Technically every value is a pointer, but you can't tell the difference unless the thing pointed to is a mutable structure. For instance, if there were a "Replace letter (n) of (string) with (letter)" command, the same issues would arise with strings.
EDIT: I keep bugging Jens for a version of = that tests pointer equality (EQ?) rather than value equality (EQUAL?), but we need suggestions about a good name for it. IDENTICAL? is one semi-standard name, but I'm not sure it's self-explanatory if you don't already know. I'm almost tempted to call it ENTANGLED?, as in quantum entanglement, where changing one particle magically changes the other one, but I'm not sure that passes the obvious-to-an-eight-year-old test. And technically entanglement is different because there really are two separate particles, whereas there's only one list if the two inputs are EQ?.
Last edited by bharvey (2012-10-02 00:11:31)
Offline
bharvey wrote:
shadow_7283 wrote:
Is there someway to prevent this behavior?
EDIT: I thought "Copy of" would do the trick, but I suppose I was wrong."Copy of" will do it unless you have a list of lists; "Copy of" does only a toplevel copy, so sublists are still identical in the two versions. You can write your own "Deep copy of" that recursively copies sublists.
I'm a little surprised that you want a deep copy, though; that's unusual.
PS It's not that the variable changes when you change the list. The value of the variable is a pointer to the list; that pointer remains constant even as the contents of the list change. Technically every value is a pointer, but you can't tell the difference unless the thing pointed to is a mutable structure. For instance, if there were a "Replace letter (n) of (string) with (letter)" command, the same issues would arise with strings.
EDIT: I keep bugging Jens for a version of = that tests pointer equality (EQ?) rather than value equality (EQUAL?), but we need suggestions about a good name for it. IDENTICAL? is one semi-standard name, but I'm not sure it's self-explanatory if you don't already know. I'm almost tempted to call it ENTANGLED?, as in quantum entanglement, where changing one particle magically changes the other one, but I'm not sure that passes the obvious-to-an-eight-year-old test. And technically entanglement is different because there really are two separate particles, whereas there's only one list if the two inputs are EQ?.
How about "[] > are the same?"
Offline
I wanted to make a value comparison between two lists- one from an older point in time in order to test for potential changes.
Offline
Offline
bharvey wrote:
EDIT: I keep bugging Jens for a version of = that tests pointer equality (EQ?) rather than value equality (EQUAL?), but we need suggestions about a good name for it.
IS?
@jens, es funktioniert alles ausser die drop-downs (oder wie sie auch immer heissen), z.B. left arrow, last, number/list/Boolean..., das mit dem Turtle Kostüm und dem About Text, der nicht übersetzt wurde (ob es auch sinnvoll wäre?)
gute Arbeit!
Last edited by roijac (2012-10-02 08:52:05)
Offline
Grr my edit to my post above didn't save...
I never liked pointers, it was always an ugly concept to me. In my perfect world, (deep)copying would be implicit. To create a pointer, you would use a special syntax, and that variable would be a pointer object, which has the original value as a property (pointer.pointee or something). I don't know how that goes down with traditional coders, but it seems much cleaner to me.
Offline
Hardmath123 wrote:
In my perfect world, (deep)copying would be implicit. To create a pointer, you would use a special syntax
That's like the C &var notation for "the address of var."
But in a really perfect world, people would program functionally, and would refrain from mutating things, and would construct a new partial list when necessary to update a value, and then the old variable would still point to the old list as shadow wants.
But, the point is, there's a difference between pointers (which are unavoidable) and making pointers visible to the user. You need pointer variables only if some values are pointers and some aren't. If every value is a pointer, as in Lisp-based languages, the user never has to see a pointer, because the language semantics automatically dereferences them. Java took a step in that direction by replacing C's pointer values with reference values, but (as with a lot of Java features) they compromised about it, leaving the references user-visible.
For the kind of huge data sets seen in real-world programming these days, putting gratuitous deep-copying into a language would really slow things down a lot!
Offline
bharvey wrote:
shadow_7283 wrote:
Is there someway to prevent this behavior?
EDIT: I thought "Copy of" would do the trick, but I suppose I was wrong.EDIT: I keep bugging Jens for a version of = that tests pointer equality (EQ?) rather than value equality (EQUAL?), but we need suggestions about a good name for it. IDENTICAL? is one semi-standard name, but I'm not sure it's self-explanatory if you don't already know. I'm almost tempted to call it ENTANGLED?, as in quantum entanglement, where changing one particle magically changes the other one, but I'm not sure that passes the obvious-to-an-eight-year-old test. And technically entanglement is different because there really are two separate particles, whereas there's only one list if the two inputs are EQ?.
<() exactly the same as ()>
<() updates to mutation of ()>
<() is the same object as ()>
some suggestions?
Last edited by joefarebrother (2012-10-02 16:55:14)
Offline
joefarebrother wrote:
bharvey wrote:
shadow_7283 wrote:
Is there someway to prevent this behavior?
EDIT: I thought "Copy of" would do the trick, but I suppose I was wrong.EDIT: I keep bugging Jens for a version of = that tests pointer equality (EQ?) rather than value equality (EQUAL?), but we need suggestions about a good name for it. IDENTICAL? is one semi-standard name, but I'm not sure it's self-explanatory if you don't already know. I'm almost tempted to call it ENTANGLED?, as in quantum entanglement, where changing one particle magically changes the other one, but I'm not sure that passes the obvious-to-an-eight-year-old test. And technically entanglement is different because there really are two separate particles, whereas there's only one list if the two inputs are EQ?.
<() exactly the same as ()>, maybe?
too long and confusing
Offline
joefarebrother wrote:
<() is the same object as ()>
Yeah, this would be the obvious choice, except that "object" is a technical term in BYOB 3.1 (and Snap! 4.1) and lists aren't objects. The others, maybe.
EDIT: Hmm, maybe "is the same list as"? Its domain could be restricted to lists.
Last edited by bharvey (2012-10-02 20:26:58)
Offline
Scripts aren't mutable (yet), right?
Offline
roijac wrote:
Hardmath123 wrote:
Scripts aren't mutable (yet), right?
but it would make sense if they would be, when jens gets to scripts manipulating
How would you even go about representing a script as something mutable? As a list-of-lists structure?
[/offtopic]
Yeah, I agree with roijac.
Offline
Hardmath123 wrote:
roijac wrote:
Hardmath123 wrote:
Scripts aren't mutable (yet), right?
but it would make sense if they would be, when jens gets to scripts manipulating
How would you even go about representing a script as something mutable? As a list-of-lists structure?
[/offtopic]
Yeah, I agree with roijac.
list of callables (blocks, lambdas, etc.)
Last edited by roijac (2012-10-03 06:00:24)
Offline
Hardmath123 wrote:
How would you even go about representing a script as something mutable? As a list-of-lists structure?
[/offtopic]
Not offtopic at all. Yes, lists of lists of values, including procedure values. But that isn't actually the internal representation of a script, so I envision a SCRIPT->TEXT block whose input is a script, reporting a list, and a TEXT->SCRIPT block that does the opposite. Or perhaps, as in Logo, a DEFINE (name) (text) block that makes a new block in the current scope from a list-of-lists. But, note, this means that scripts themselves would not be mutable. You'd turn the script into a list, mutate that, and create a new script that might replace the old one as the definition of a block.
Sprites, though, are a better argument, since they have local state variables and are therefore already mutable.
The trouble with () POINTS TO (), in my mind, is that it suggests an asymmetry: the left input has data type "pointer" and the right one doesn't. COLOCATED WITH says exactly the right thing, but it's a mouthful. Maybe we should just stick with EQ? or, for non-Lispers, ==.
Offline
bharvey wrote:
Hardmath123 wrote:
How would you even go about representing a script as something mutable? As a list-of-lists structure?
[/offtopic]Not offtopic at all. Yes, lists of lists of values, including procedure values. But that isn't actually the internal representation of a script, so I envision a SCRIPT->TEXT block whose input is a script, reporting a list, and a TEXT->SCRIPT block that does the opposite. Or perhaps, as in Logo, a DEFINE (name) (text) block that makes a new block in the current scope from a list-of-lists. But, note, this means that scripts themselves would not be mutable. You'd turn the script into a list, mutate that, and create a new script that might replace the old one as the definition of a block.
Sprites, though, are a better argument, since they have local state variables and are therefore already mutable.
The trouble with () POINTS TO (), in my mind, is that it suggests an asymmetry: the left input has data type "pointer" and the right one doesn't. COLOCATED WITH says exactly the right thing, but it's a mouthful. Maybe we should just stick with EQ? or, for non-Lispers, ==.
maybe rename <() = ()> to <() equals ()> and then we have also <() is ()>? then the difference is clearer.
#scripts, i suggest to implement scripts as lists of blocks, and make kind of (args of ()) block or something. what do you say?
Offline
roijac wrote:
#scripts, i suggest to implement scripts as lists of blocks, and make kind of (args of ()) block or something. what do you say?
Umm, well, in the abstract there's a lot to be said for that point of view, but the Morphic Way says to interweave script evaluation with the visual representation of scripts tightly, so that the actual script representation is mostly about what it looks like and only secondarily about the evaluation semantics. So I'll let you and Jens argue about it.
Offline
@bharvey
" as in Logo, a DEFINE (name) (text) block that makes a new block in the current scope from a list-of-lists."
As far as I remember (30 years ago !) the DEFINE Logo procedure is composed of a header (name of the procedure), then a kind of "constructor" and the "body" made from a list (or list-of-lists)...The result is that you can change "interactively", directly from an application the nature and the role of the procedure created by DEFINE (adding or deleting items).It' s a self-adaptive custom block. This could probably be emulated in Snap! using C-Shape like instructions.
Offline
xly wrote:
adding or deleting items
I'm not positive exactly what you mean by this. Once you DEFINE a procedure, changing the list from which the procedure was made doesn't change the procedure, I'm pretty sure. You can say DEFINE again to make a new procedure that replaces the old one of the given name.
One important difference between Logo and Snap! is that in a dynamically scoped language, a procedure is nothing but its text, whereas in a lexically scoped language, a procedure is the text plus the environment in which the procedure was created. So, I guess in addition to SCRIPT->TEXT we need SCRIPT->ENVIRONMENT or something.
And maybe DEFINE should take an environment as input. Otoh, first class environments are expensive in that certain compiler optimizations don't work if users can mess with environments.
Offline
How about a list-of-list structure of lambdas?
when gf clicked say ((1)+(1))
becomes
[ [when gf clicked], [say, [+, 1, 1]] ]
where +, say, and when gf clicked are actually the lambda (the () block) versions rather than text? You'll also need a (lambda = lambda?) operator, though.
Offline
@bharvey
"DEFINE a procedure, changing the list from which the procedure ..."
1 - To define - in Apple ][ Logo - the custom block SQ you write it "by hand" in the script area.
TO SQ :N
RT :N * :N
END
2 - But you can also build this block inside your application as a list of list using DEFNE procedure :
DEFINE "SQ [[N][RT :N * :N]
3 - But DEFINE has a "reverse" procedure -TEXT -which gives the content of one custom block as a list-of-list.
TEXT "SQ returns [[N][RT :N * :N]
This list-of-list can be modified modify and then reloaded with DEFINE, and you get a new block with the same name (or another name if needed , clone, for example) which can be run directly from your application.
Offline