cardinal-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cardinal-dev] Questions, ideas and thoughts


From: Erik Bågfors
Subject: [Cardinal-dev] Questions, ideas and thoughts
Date: 15 May 2002 20:44:03 +0200

Hello

Like I said before when I created my basic-compiler I got lot's of
questions. Unfortunately I've forgotten some of them and I have very
little time for writing that large mail. So here are just a few
questions, ideas, thoughts.

I'm only sending them to the cardinal-list since lot's of them has to do
with ruby and some with only parrot.

Most questions are regarding the use of multiple languages in parrot.
I've looked at .Net and there all languages must follow some rules such
as, they must be object oriented (well, they need to handle working with
objects anyway), they can't have multiple inheritance and more. (note,
I'm not talking about how bad .Net is for dynamic languages.. that's a
totally different issue altogether)

The whole point of running languages on another VM/interpreter than the
default one is to be able to do some cool inter-language-stuff.

So writing my really really small basic-like language I started to think
how I could call ruby or perl-code from it and quickly realized that it
needed to understand objects in some way. This can be done very easy and
without putting objects into the language itself like the following

# Ruby code
class TestClass
        def initialize(string)
                @string = string 
        end
        def a(string)
                puts "Initialized with " + @string
                puts "Called a with " + string
        end
end

# Called from ruby code
test = TestClass.new("test")
test.a("more test")                     # This would output
                                        # Initialized with test
                                        # Called with more test

# My basic-code could look like this
TEST = TestClass_new("test")
TestClass_a(TEST, "more test")               # which would give it a
gtk+-like syntax.

That should work shouldn't it?
So.. in that way we should be able to solve the
none-oo-language-using-objects-problem.  This needs some kind of naming
convention for how classes/object/methods should be named.  How are
classes and objects defined in parrot and parrot assembly??


what about this code in ruby?
def four_times
        yeild
        yeild
        yeild
        yeild
end

How would I call this code from my minibasic? or from perl?? or from
scheme? Is that even possible? rubys block are wonderfull and I'd like
to use them alot :)


Another example is that in ruby all classes need to start with a capital
character.  That means that a class written in another language that
doesn't have this restriction is either a) unusable or b) usable if we
rename it somehow of c) usable if we change ruby.  What would we do
here?


One change I think we will have to do is true and false-values.  In ruby
only "nil" and "false" evaluates as false in if/while/for/.... If I use
something from perl that is false I think it must evaluate as false in
ruby also.  This will be quite easy to do since parrot kinda solves this
for us, but it will feel wierd when 0 can be false again (if it's not a
Ruby 0 :) )


Another question is regarding types in the languages.  For example

# Perl-code
sub hello  { "1234" }
sub hello2 { 1234 }

$h = hello;
$h2 = hello2;
print "number equal\n" if $h == $h2;
print "string equal\n" if $h eq $h2;
# End code

This code will produce the output 
number equal
string equal

because hello and hello2 both outputs a scalar, which in perl is both
string and numbers.  
Calling this from ruby can give us several ways of doing that. One is
that we should be avare that what is being returned from the subrutines
are infact PerlScalars and not RubyStrings or RubyNumbers.  That would
give us the following code

require "perlcode"
h = hello
h2 = hello2 # Both h and h2 are PerlScalars

puts "number equal" if h == h2   # if == is defined as a method in
PerlScalar
puts "string equal" if h.eq h2   # if eq is defined as a method in
PerlScalar 

The other way of doing it is to have somekind of automatic conversion to
either RubyNumbers of RubyStrings.

require "perlcode"
h = hello 
h2 = hello # Both h and h2 are now normal ruby strings

puts "string equal" if h == h2
puts "number equal if h.to_i == h2.to_i


This would require some kind of magic conversion within parrot.  Of
course this also get's very interesting because you'll get strings back
from mathematical functions.

The other way is also interesting.  Calling ruby from perl. For example
without the magical conversion I talk about above:

# Ruby code
def constant_number
        0
end

# perl code
print "true" if (constant_number);

Will ALWAYS print true since RubyIntegers are always true, even the
number 0.  That will really confuse the perl-guys.

How do we call functions from ruby? In ruby (as all real oo-languages)
there is really no such thing as functions, only methods.  Do we just
throw the functions as methods into the Kernel class?  That seams
logical since that's kindof what ruby does if you define a method
without saying what class it should belong to.


Also, where do I find good info on how functions/methods are supposed to
work in parrot.  The examples on parrotcode.org shows some basic ideas
but there are lot's of things missing and I know there has been talk
about this lately in perl6-internals but I don't know what the final
word was.

/Erik

-- 
Erik Bågfors               | address@hidden
Supporter of free software | GSM +46 733 279 273
fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32



reply via email to

[Prev in Thread] Current Thread [Next in Thread]