Home   Archive   Permalink



newbie questions

Hi, I'm working through the REBOL essentials tutorial and have got the section on series where it says that assigning series to a word is always done by reference so you should use "copy" to avoid unexpected behaviour. However I'm a little puzzled by what appears to be an inconsistency (I'm sure it isn't, but this is how it seems to me until I'm put right).
    
Example:
    
>> a: [1 1] ; assign to a
== [1 1]
>> b: a ; assign a to b
== [1 1]
>> b
== [1 1]
>> append a 2
== [1 1 2]
>> b
== [1 1 2]
>> unique a
== [1 2]
>> b
== [1 1 2]
    
After assigning a to b (which was initially []) when I append to a then b is also changed, but when I use the "unique" function on a then b is NOT changed, why not?
    


posted by:   Mike     24-Mar-2011/6:30:29-7:00



Try
    
a
    
You'll see that it is still the original series, the same as b, because you didn't reassign a.
    
Many functions do an implicit COPY to make programming safer and, hopefully, less surprising.

posted by:   Kaj     24-Mar-2011/12:16-7:00



Thanks Kaj. I must admit I'm finding this confusing.
    
Here's the example with a reassigned:
    
>> a: [1 1]
== [1 1]
>> b: a ; assign a to b
== [1 1]
>> b ; b is now the same as a
== [1 1]
>> a: append a 2
== [1 1 2]
>> b
== [1 1 2] ; b is now also a
>> ; now get unique a
>> a: unique a
== [1 2]
>> b
== [1 1 2] ;b isn't affected
    
It just seems a little arbitrary that UNIQUE does COPY but APPEND doesn't. How do I find out which functions do an implicit COPY and which don't?
    
Or have I misunderstood completely?

posted by:   Mike     24-Mar-2011/13:18:09-7:00



You can somehow guess which one changes the series,
    
append, insert, change, poke: changes the current series.
    
intersect, unique, union: creates a new one(copies)
    
but "sort" is difficult to guess :) it modifies the series.
    
Please check this http://www.rebol.com/docs/dictionary.html find the section "Modifying (Series) Functions"


posted by:   Endo     24-Mar-2011/13:48:20-7:00



Thanks Endo. I don't have much programming experience but from what I've read that's not a bad thing. :-)
    
I'm sure I'll have more questions later.

posted by:   Mike     24-Mar-2011/14:38:08-7:00



It is definitely a good thing when you are new about programming and learning Rebol :)
One of my friends writes very nice utitilies for his job and he did learn Rebol just in a few weeks and just by asking question by email to me :)
Feel free to ask your questions here.


posted by:   Endo     25-Mar-2011/9:29:56-7:00



It's like learning a human language, so after a while you'll get fluent without really noticing. :-)
    
UNIQUE is hard to guess because it operates on one series. As Endo noted, by consistency with the other set operations that combine two sets, it copies.
    
There was recently a discussion about UNIQUE. It was requested that it would not copy, for memory efficiency (like SORT). But apparently, the way UNIQUE is implemented, it ends up with a copy anyway, so you might as well give it the safe behaviour consistent with the other set operations.

posted by:   Kaj     25-Mar-2011/10:16:44-7:00



This post probably belongs in another thread but I wasn't able to reply to it.
    
I'm setting up a web site and am hoping to use REBOL for CGI (when I learn how to do it!). The basic template of the site uses PHP and mysql. My question is: does the fact that large parts of the site need PHP exclude me from using REBOL for other GCI code I might want to implement in the future?
    
I think the answer is no but I just wanted to check.
    


posted by:   Mike     29-Mar-2011/6:17:18-7:00



Just to clarify the above, many web hosts offer a number of languages for scripting such as PHP, perl, Python etc, but is there any requirement that you use only one of them or can you select whatever you find most useful for a particular application?
I don't know whether there's any technical reason why you might have to choose one language and stick to it.

posted by:   Mike     29-Mar-2011/6:45:32-7:00



CGI is modular, so you can write each CGI in a different language.
    
But please create a new topic for new questions.

posted by:   Kaj     29-Mar-2011/10:08:10-7:00



Thanks Kaj.
    
Yes, sorry. I wanted to add to the thread titled
"REBOL CGI Hosting" in the archive but there was no field at the bottom of the page for me to reply.

posted by:   Mike     29-Mar-2011/11:59:40-7:00



As Kaj said, CGI is a general system and almost all the web servers / hosting services support it.
You can choose the language that you want to use freely. PHP, perl etc. usually comes pre-installed on the servers that's the difference.
    
You can create a new topic from home page not from inside another topic.


posted by:   Endo     30-Mar-2011/12:00:58-7:00