Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Dumb newbie Rebol question

 [1/15] from: parki::whatevernot::com at: 4-Sep-2003 18:51


Why a: copy "" as opposed to simply a: "" I am assuming bad side effects - can someone enlighten me? Thanks, parki... ps. I bought Rebol, tthe Official Guide - am I right in assuming that I need the Core Guide as well? I'm looking more for a reference, and something that'll get me into some technical details (esp as regards to dialects).

 [2/15] from: andrew:martin:colenso:school at: 5-Sep-2003 11:21


> Why > a: copy "" > as opposed to simply > a: ""
I am assuming bad side effects - can someone enlighten me?
>> F: function [A] [S] [S: "" insert S A S] >> f 1
== "1"
>> f 3
== "31"
>> source f
f: func [A /local S][S: "31" insert S A S] Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [3/15] from: carl::cybercraft::co::nz at: 24-Dec-2003 22:34


Hi Brian, On 05-Sep-03, Brian Parkinson wrote:
> Why > a: copy "" > as opposed to simply > a: "" > I am assuming bad side effects - can someone enlighten me?
Not so much bad effects, as different ones. 'copy creates a new instance of the string, whereas without it REBOL will use the original instance, which may have been modified. Ummm - much easier to show than explain...
>> loop 3 [a: "" append a "cat" print a]
cat catcat catcatcat
>> loop 3 [a: copy "" append a "cat" print a]
cat cat cat
> Thanks, > parki... > ps. I bought Rebol, tthe Official Guide - am I right in assuming > that I need the Core Guide as well? I'm looking more for a > reference, and something that'll get me into some technical details > (esp as regards to dialects).
I find it's the Core Guide I turn to first when I need info I can't get with the Console's help. It's available on the rebol.com site in HTML and PDF, so you can check it out before you buy. It has a chapter on parsing and dialects... http://www.rebol.com/docs/core23/rebolcore-15.html Hope that helps - and welcome to REBOL. -- Carl Read

 [4/15] from: parki:whatevernot at: 4-Sep-2003 19:53


Thanks. Time to step up the learning curve (it seems, well, so *weird* from a Java/C perspective :-) :-) :-) Cheers, parki... On Thursday, September 4, 2003, at 07:21 PM, Andrew Martin wrote:

 [5/15] from: greggirwin:mindspring at: 4-Sep-2003 18:32


Hi Brian, BP> Time to step up the learning curve (it seems, well, so *weird* from a BP> Java/C perspective :-) :-) :-) It is something you have to think about, and get wrong a few times, before you start to really be aware of it, but it's not bad after you adjust a bit. :) The big thing to be aware of is that the rule applies to all series! types (e.g. blocks), not just strings. Another thing to keep in mind, that's different, is how references to series! values are really a "current position" marker, kind of like a cursor. When you use NEXT, BACK, etc. you're really moving that marker in the series rather than modifying the series itself. I've been REBOLing for about two years now, and I like it more every day. After adjusting to how it works (at some point you'll hear an audible "click" in your head ;) life is great. Actually, I *still* hear a lot of clicks in my head, but in a good way. Not like "Man, I can't believe how hard that was to understand"; more like "Man, I can't believe how hard I was making things when I can just do *this*." -- Gregg

 [6/15] from: brett:codeconscious at: 5-Sep-2003 10:28


> Time to step up the learning curve (it seems, well, so *weird* from a > Java/C perspective :-) :-) :-)
Yes, very different from some compiled languages! You might find something of interest here: http://www.codeconscious.com/rebol/articles/rebol-concepts.html Brett.

 [7/15] from: parki:whatevernot at: 4-Sep-2003 23:01


Wow - help on this list is great. Having fun putting together the X.10 control stuff - will soon be able make available sample Rebol code to control X.10 lights - reading up on dialects right now. Cooooool. But have a couple 00 questions: 1. Data encapsulation - is there any convenient way to make data readonly in an object? I need to define some constants, and I want to put them in an object so as to not clutter up the namespace. I thought this might work, but it does not: x: make object! [ a: 13 protect 'a ] 2. Any way to enforce some sort of Singleton idiom? I suspect that asking this (and perhaps the above) are caused by not enough indoctrination to the Rebol way of doing things, but wondering... I am going to put the serial connection code into an object (again, keep namespaces clean) and in Java, I'd make this a Singleton, as I only want one serial connection open. Not sure how this should be tackled in Rebol. Hot dang - this is a fun language! Cheers, parki...

 [8/15] from: andrew:martin:colenso:school at: 5-Sep-2003 15:19


parki wrote:
> But have a couple 00 questions: > > 1. Data encapsulation - is there any convenient way to make data
readonly in an object? I need to define some constants, and I want to put them in an object so as to not clutter up the namespace. I thought this might work, but it does not:
> x: make object! [ > a: 13 > protect 'a > ]
Can't really make a value read-only in a object in Rebol. But this kind of thing might be helpful:
>> use [x_a] [
[ x_a: 123 [ x: make object! [ [ a: does [x_a] [ ] [ ]
>> probe x
make object! [ a: func [][x_a] ]
>> x/a
== 123
>> x_a
** Script Error: x_a has no value ** Near: x_a Note that 'x_a and it's value are not (easily) accessible outside the object. This kind of thing can be helpful in making only one of a thing, by making the value of 'x_a an object! inside the object referred to by 'x. Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/
> -----Original Message----- > From: Brian Parkinson [mailto:[parki--whatevernot--com]]
<<quoted lines omitted: 41>>
> To unsubscribe from this list, just send an email to > [rebol-request--rebol--com] with unsubscribe as the subject.
DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [9/15] from: andrew:martin:colenso:school at: 5-Sep-2003 15:31


parki wrote:
> 2. Any way to enforce some sort of Singleton idiom? I suspect that
asking this (and perhaps the above) are caused by not enough indoctrination to the Rebol way of doing things, but wondering... I am going to put the serial connection code into an object (again, keep namespaces clean) and in Java, I'd make this a Singleton, as I only want one serial connection open. Not sure how this should be tackled in Rebol. I'd have it something like this: Your outside script does something like this: do %X10.r ; Call the X10 script. And your %X10.r script looks something like this: Rebol [ File: %X10.r ;... ] if not value? 'X10 [ X10: make object! [ ] ] So, even if the outside script does silly things like this: do %X10.r ; Call the X10 script. do %X10.r ; Call the X10 script. do %X10.r ; Call the X10 script. You'll only get the one object referred to by the word 'X10. I hope that helps! Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [10/15] from: andrew:martin:colenso:school at: 5-Sep-2003 15:48


> So, even if the outside script does silly things like this: > do %X10.r ; Call the X10 script. > do %X10.r ; Call the X10 script. > do %X10.r ; Call the X10 script. > > You'll only get the one object referred to by the word 'X10.
Of course, if your code does perverse things like: do %X10.r ; Call the X10 script. X10: none ; ... And get rid of object. do %X10.r ; Call the X10 script. X10: none ; ... And get rid of object. do %X10.r ; Call the X10 script. X10: none ; ... And get rid of object. Then you'll get several creations of the object referred to by the word 'X10. Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [11/15] from: parki:whatevernot at: 4-Sep-2003 23:56


Thanks - brilliant solutions to both my problems. Next up - The power of dialectics :-) parki... --- x8 snip On Thursday, September 4, 2003, at 11:31 PM, Andrew Martin wrote:

 [12/15] from: greggirwin:mindspring at: 4-Sep-2003 22:20


Hi Brian, (or do you prefer Parki?) BP> Wow - help on this list is great. Yes, it is. Part of why I love REBOL is the people it attracts. BP> 1. Data encapsulation - is there any convenient way to make data BP> readonly in an object? I need to define some constants, and I want to BP> put them in an object so as to not clutter up the namespace. Not really. I had the same issue when I started with REBOL, but I haven't missed them (constants) for a long time. One thing that helped me was when I tried to emulate ENUM functionality in REBOL ("How could they leave that out?!" :). At some point in the process, I realized that I didn't really need the numeric values for anything; what I wanted were the human-friendly words that were unique in a list. From there it was a short jump to just using a block of words and using the literal words themselves. Another thing that I think has helped me is keeping things small and using objects to prevent "accidents". Rather than blindly including every API constant listed in a Windows header file (as I would do under VB), I include only those I need, maybe putting the others in as comments. I had a hard time getting out of my strong OO mindset and into a more build just what you need right now kind of mentality, and I still have issues to sort out myself, but it *can* work. :) Maybe if you show us exactly what you're wanting to do, we can make some suggestions. That's another thing about REBOL, you can often come up with a great *specific* solution that is not easily generalizable. BP> 2. Any way to enforce some sort of Singleton idiom? I suspect that BP> asking this (and perhaps the above) are caused by not enough BP> indoctrination to the Rebol way of doing things, but wondering... I am BP> going to put the serial connection code into an object (again, keep BP> namespaces clean) and in Java, I'd make this a Singleton, as I only BP> want one serial connection open. Not sure how this should be tackled in BP> Rebol. Same kind of deal. There's no mechanism to enforce it, but you just create "the one" and use that. Maybe you end up with an outer object that contains your serial singleton object, so he's the one responsible for not creating more than one of them. Again, looking at the specific case will sometimes lead to ideas about an architecture. Lexical scoping is another tool you can put to good use in REBOL. BP> Hot dang - this is a fun language! I couldn't agree more! :) -- Gregg

 [13/15] from: maarten:vrijheid at: 5-Sep-2003 7:39


> a: "" > I am assuming bad side effects - can someone enlighten me?
<<quoted lines omitted: 4>>
> == "31" > >> source f
Think of this as the default behaviour is that of a static variable in Java/C++, if you use 'copy it becomes instance-like. Now forget Java ;-)

 [14/15] from: maarten:vrijheid at: 5-Sep-2003 7:42


> >> use [x_a] [ > [ x_a: 123
<<quoted lines omitted: 13>>
> Note that 'x_a and it's value are not (easily) accessible outside the > object. This kind of thing can be helpful in making only one of a
thing,
> by making the value of 'x_a an object! inside the object referred to
by
> 'x.
This trick is creating an anonymous 'use context that can be useful to create the equivalent of a hidden stack frame and thus manipulate how the interpreter reacts to some stuff. For example, bot Ladislav and I have implemented tail recursion eleminiation exactly the same using a use [ ..... ][ .... func [ ] []] construct. And there is your singleton! Use [ single x10 ][ single: no func [][either single [ x10][x10: some-new-object single:yes]] --Maarten

 [15/15] from: nitsch-lists:netcologne at: 5-Sep-2003 18:36


Am Freitag, 5. September 2003 05:01 schrieb Brian Parkinson:
> Wow - help on this list is great. > Having fun putting together the X.10 control stuff - will soon be able
<<quoted lines omitted: 9>>
> protect 'a > ]
see below. And as Gregg said, if you need enums, use words directly :)
> 2. Any way to enforce some sort of Singleton idiom? I suspect that > asking this (and perhaps the above) are caused by not enough
<<quoted lines omitted: 3>>
> want one serial connection open. Not sure how this should be tackled in > Rebol.
rebol-objects are singletons. its possible to make them "multitons" to. the "class-declaration" itself is a usable object. thats the something: context[..] is a shortcut for something: make object![..] for constant-checking, since 'protect is broken, you could check often: constants: context[a: 1 b: 2] constants-backup: make constants [] constants/a: 3 if (third constants) <> third constants-backup [alert "changed!"] wrap the last line in a function and call it often.
> Hot dang - this is a fun language! >
!!! :)
> Cheers, > > parki... >
-Volker

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted