1. [phix] if 'number' then why not 'list' ?

An atom is:

  • number
  • integer

A list is:

  • sequence
  • string

since a sequence is, not quite, a superset of string

For generic tutorial descriptions emphasis on "only two distinct data-types" is a selling point. You just have to understand "atom" and "list". If you just have to use: number, integer, sequence, string

Writing a demo program that uses just number and list gets as simple as it gets. Everyone (like non-programmers) understand what a number is and a what list is--no thinking required.

be well
_tom

new topic     » topic index » view message » categorize

2. Re: [phix] if 'number' then why not 'list' ?

list does carry a lisp-like connotation, and the implication that random access is expensive. Maybe.

Wikipedia (groan) states "Some languages may allow list types to be indexed or sliced like array types, in which case the data type is more accurately described as an array."

And array generally implies fixed length and homogenous element type.

new topic     » goto parent     » topic index » view message » categorize

3. Re: [phix] if 'number' then why not 'list' ?

  • 1 is a number
  • 3.1415 is a number
  • "Hello" is a string

What is {1} ? (a container containing one number)
What is {1,2,3.14} ? (a container containing a sequence of 3 numbers)

What is {"Hello",1,2} ? (a container containing 1 string and 2 numbers)
What is {"Hello",{1,2,3}} ? (a container containing 1 string and 1 sequence of 3 numbers)

Maybe the word container would make the concept easier to explain?

new topic     » goto parent     » topic index » view message » categorize

4. Re: [phix] if 'number' then why not 'list' ?

irv said...
  • 1 is a number
  • 3.1415 is a number
  • "Hello" is a string

What is {1} ? (a container containing one number)
What is {1,2,3.14} ? (a container containing a sequence of 3 numbers)

What is {"Hello",1,2} ? (a container containing 1 string and 2 numbers)
What is {"Hello",{1,2,3}} ? (a container containing 1 string and 1 sequence of 3 numbers)

Maybe the word container would make the concept easier to explain?

I like this suggestion. It allows me to include struct and class under "container."

be well
_tom

new topic     » goto parent     » topic index » view message » categorize

5. Re: [phix] if 'number' then why not 'list' ?

_tom said...
irv said...

Maybe the word container would make the concept easier to explain?

I like this suggestion. It allows me to include struct and class under "container."

Uh oh, i like it too. Objects in sequences do not need to be sequential.

I figured out the bug tho: down the road all incoming newbies will replace the word sequence totally with container. Eu/OE/Phix will lose this verbal claim to fame.

Kat

new topic     » goto parent     » topic index » view message » categorize

6. Re: [phix] if 'number' then why not 'list' ?

said...

Maybe the word container would make the concept easier to explain?

_tom said...

I like this suggestion. It allows me to include struct and class under "container."

be well
_tom

Perhaps a struc is a container containing a specified number of [typed] objects, as opposed to the freestyle sequence, which can contain anything in any quantity.

And a class is a container containing numbers, strings, sequences and/or objects, plus methods, all associated with the specific class.

new topic     » goto parent     » topic index » view message » categorize

7. Re: [phix] if 'number' then why not 'list' ?

irv said...

What is {1,2,3.14} ? (a container containing a sequence of 3 numbers)
What is {"Hello",{1,2,3}} ? (a container containing 1 string and 1 sequence of 3 numbers)

Minor nit-pick: assuming that 'a' and '1' mean the same thing, only one of those can be correct, and I think it's the 2nd.
Minor nit-pick number two: does that mean we now have to describe container and sequence?
Minor nit-pick number three: the phrases "sequence contains" and "sequence containing" work for me, "container contains" and "container containing" not so much.
Minor nit-pick number four: I suspect you'd have to define "container" with just as much care as "sequence"

Now over 20 years ago, Rob Craig said:
"sequences make Euphoria very simple and very powerful"
"Sequences are it - there are no other data structures to learn."

More than anything else, those two phrases still resonate deeply with me, even after all this time.
If you try and use a word that someone likely has preconceptions about, such as list or array, that loses it's punch, and pretty much stops making any sense altogether.

new topic     » goto parent     » topic index » view message » categorize

8. Re: [phix] if 'number' then why not 'list' ?

petelomax said...
irv said...

What is {1,2,3.14} ? (a container containing a sequence of 3 numbers)
What is {"Hello",{1,2,3}} ? (a container containing 1 string and 1 sequence of 3 numbers)

Minor nit-pick: assuming that 'a' and '1' mean the same thing, only one of those can be correct, and I think it's the 2nd.
Minor nit-pick number two: does that mean we now have to describe container and sequence?
Minor nit-pick number three: the phrases "sequence contains" and "sequence containing" work for me, "container contains" and "container containing" not so much.

Yes. Containing 1 sequence of 3 numbers is clearer.

Yes. Trying to explain that structs and classes are also types of sequences is just going to complicate things, since they aren't really treated like other sequences.

Agreed.

new topic     » goto parent     » topic index » view message » categorize

9. Re: [phix] if 'number' then why not 'list' ?

Question about class, in Phix/OE, to simplify perhaps (or too simplified?)....

Can you express class as like an include file with everything in it scoped to that thing you just classed?

Kat

new topic     » goto parent     » topic index » view message » categorize

10. Re: [phix] if 'number' then why not 'list' ?

Everything in a class is scoped to an instance of that class.

new topic     » goto parent     » topic index » view message » categorize

11. Re: [phix] if 'number' then why not 'list' ?

petelomax said...

Everything in a class is scoped to an instance of that class.

So class is not like an include file?

Kat

new topic     » goto parent     » topic index » view message » categorize

12. Re: [phix] if 'number' then why not 'list' ?

No, you cannot have an include statement inside a class definition.

new topic     » goto parent     » topic index » view message » categorize

13. Re: [phix] if 'number' then why not 'list' ?

Still not what i said.

Is a class like a include file, with everything in the include file scoped to what you declared as a class?

The what's different about "include as"?

include cow.e as cow_1  
include cow.e as cow_2 

Now both cows have variables and procedures and functions (from cow.e) as most cows do. Are they treated same as a class?

Kat

new topic     » goto parent     » topic index » view message » categorize

14. Re: [phix] if 'number' then why not 'list' ?

Not the same. Here is a comparison:

-- contents of cow.e---- 
public integer horns = 0 
------------------------ 
 
include cow.e as cow1 
include cow.e as cow2 
 
cow1:horns = 2 
cow2:horns = 1 
 
? cow1:horns 
? cow2:horns 

1 
1 

As you can see, there is only one variable to store the # of horns, even if you use different "namespaces".


On the other hand, classes provide a "horns" variable for each instance of cow, so we change cow.e so that it declares a class:

export class Cow  
    public integer horns = 0; 
end class 
include cow.e  
 
Cow cow1 = new() 
Cow cow2 = new() 
 
cow1.horns = 2 
cow2.horns = 1 
 
? cow1.horns 
? cow2.horns 

2 
1 


More often than not, I will declare methods which are called when the number of horns on any cow is accessed, so the cow class would look more like this:

export class Cow 
    private integer horns; 
 
    procedure set_horns(integer n) 
     this.horns = n 
    end procedure 
     
    function get_horns() 
     return this.horns 
    end function 
     
end class 

Within those methods, you can do other stuff that might be needed, like popping up a warning if someone tries to give Bessie 3 horns...etc.

new topic     » goto parent     » topic index » view message » categorize

15. Re: [phix] if 'number' then why not 'list' ?

katsmeow said...

Still not what i said.

Still no idea what the question is.

katsmeow said...

Is a class like a include file, with everything in the include file scoped to what you declared as a class?

What part of "Everything in a class is scoped to an instance of that class." does not answer that question?

katsmeow said...

Now both cows have variables and procedures and functions

They most certainly do not (as irv just posted while I was typing). There is one cow that can be referenced via two namespaces.

An include statement includes a file.
A class statement defines a class.
There are some minor similarities and many more vast differences.
A new class instance can be created using new(). An include instance just is.
An include can contain global and non-global definitions, which are and are not visible.
A class can have public and private fields, but they don't exist except via an instance, and only then does externally visible or internal only apply.
"Yes they are similar" and "No they are completely different" are both true at the same time.
If you had bothered to read even the first line of the manual you would know that classes are much closer to types than include statements.

new topic     » goto parent     » topic index » view message » categorize

16. Re: [phix] if 'number' then why not 'list' ?

Hmm, ok. Thanks, Irv.

I hate to ask, it seems like an old question, but if i have a mammal class, can a cow class inheret from the mammal class? (speaking about Phix and OE implementations)

Kat

new topic     » goto parent     » topic index » view message » categorize

17. Re: [phix] if 'number' then why not 'list' ?

Phix:Yes OE:???

However, as the Gang of Four said nearly thirty years ago, favour composition over inheritance.

new topic     » goto parent     » topic index » view message » categorize

18. Re: [phix] if 'number' then why not 'list' ?

katsmeow said...

Hmm, ok. Thanks, Irv.

I hate to ask, it seems like an old question, but if i have a mammal class, can a cow class inheret from the mammal class? (speaking about Phix and OE implementations)

Kat

Phix, yes. OE, no.

That's exactly where classes are useful. e.g:

export class Mammal 
  public string gender; 
end class 
 
export class Whale extends Mammal 
end class 
 
export class Cow extends Mammal 
    public integer horns; 
end class 
 
include Cow.e 
 
Cow Bossie = new() 
Cow Ferdinand = new() 
Bossie.gender = "female" 
Ferdinand.horns = 2 
Whale Nemo = new() 
Nemo.gender = "male" 
Nemo.horns = 2 -- no such field (horns) is the error message; 

You'll note that it isn't necessary for your program to specifically include a file declaring the Mammal class. The Cattle file will include that, and look for the "gender" variable in that class (or classes, as the case may be - multiple inheritance is easy to do, the planning part is difficult.)

new topic     » goto parent     » topic index » view message » categorize

19. Re: [phix] if 'number' then why not 'list' ?

petelomax said...

If you had bothered to read even the first line of the manual you would know that classes are much closer to types than include statements.

I don't know where my reply to that went, but it's been 5 minutes or so...

Since i was working around the type system to make shared variables possible, i first considered type. But type as implemented in OE, doesn't let the programmer know the variable name being type-checked. I had to jump hoops to get that data. And the code written (procedures and functions) aren't exclusively naturally available to the variable the type check was written for. And finally, the resulting code block would/could look like an include file. Which is how i got to asking about "class" vs "include as".

Kat

new topic     » goto parent     » topic index » view message » categorize

20. Re: [phix] if 'number' then why not 'list' ?

katsmeow said...

Since i was working around the type system to make shared variables possible, i first considered type. But type as implemented in OE, doesn't let the programmer know the variable name being type-checked. I had to jump hoops to get that data. And the code written (procedures and functions) aren't exclusively naturally available to the variable the type check was written for. And finally, the resulting code block would/could look like an include file. Which is how i got to asking about "class" vs "include as".

Kat

Yep. When Rob first implemented the "include as", it was possible to do multiple includes under different namespaces, and have separate instances of a variable. That didn't last long, he quickly "fixed" it - presumably due to side effects (he didn't share). If it had been combined with an improved type() implementation, as you point out, Euphoria would have had OOP decades ago - but probably not with inheritance. Phix does that nicely.

new topic     » goto parent     » topic index » view message » categorize

21. Re: [phix] if 'number' then why not 'list' ?

irv said...

Yep. When Rob first implemented the "include as", it was possible to do multiple includes under different namespaces, and have separate instances of a variable. That didn't last long, he quickly "fixed" it - presumably due to side effects (he didn't share).

Thank you Irv, it's been enlightening.

With a slight change to the shared variables preprocessor, i can include cow.e as something file many times, once for each umm, situation, being it's understood every variable and code block has a different name, based on the something in the include declaration, accessed approximately like class naming does. It's only a way to get around the "fix" Rob did to the original "bug", and it's going to grow the load time and memory use accordingly.

Kat

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu