Stoppt die Vorratsdatenspeicherung! Jetzt klicken &handeln! Willst du auch an der Aktion teilnehmen? Hier findest du alle relevanten Infos
  und Materialien:

Skip to content


Blocktalk: Dealing with classes & modules

Alright. I’ve renamed my language again: Blocktalk is what I’ve settled on (finally I hope).
I think it resembles a little more the Smalltalk heritage, although most implementation related concepts come from Ruby though. Oh well, I like the name better, so that’s why i chose to name it that way.

Current progress:
Class & module definitions work correctly now, meaning that it now fully supports nearly all concepts that you find in Ruby. The main difference is, that in contrast to Ruby, Blocktalk does not have any real Keywords predefined, except for just a few including:

  • def (for indicating method definitions)
  • do & end (for codeblocks)
  • self (the same as in Ruby & Smalltalk: reference to the current object)
  • return (explicitly returning from withing the middle of a method)
  • yield (same as in ruby: yielding to a given implicit block)
  • Some literal syntax (not real Keywords, but somehow belongs into this category) for Arrays, Hashes, Codeblocks, Integers, Floats, Strings, Symbols, Characters and of course Assignment

That’s pretty much it, regarding predefined keywords in the language itself. Everything else relies on expressions like message passing (a.k.a. method calling) to objects, assignments and arithmetic. Even defining new modules or classes is done by sending a message to the Class or Module class-object (very similar to how it’s done in Smalltalk and how you can also do it in Ruby).

Here’s a small example of defining a class and a module:

Module >> :ModuleA do
  def method_a = do
    Console puts: "in ModuleA#method_a!"
  end
end
 
 
Module >> :ModuleB do
  def method_b = do
    Console puts: "in ModuleB#method_b!"
  end
end
 
Class >> :Place do
  def 1/>self from_city = do |city_name|
    # should do something useful here ...
    Place new
  end
 
  def coordinates = do
    # do some calculation here...
    return (Kernel rand)
  end
end
 
Class >> :Person do
  1/>self mixin: [ModuleA, ModuleB]
 
  # constructor with named params
  def initialize = do |name age: age city: city|
    @name = name
    @age = age
    @city = city
  end
 
  def go_to = do |place with: vehicle|
    ((place is_a?: Place) and: ((1/>self distance_to: place) < 10.5)) if_true {
      vehicle take: 1/>self to: place
    }
  end
 
  def place = do
    Place from_city: @city
  end
 
  def distance_to = do |place|
    (place is_a?: Place) if_true: {
      dist = ((1/>self place) coordinates) - (place coordinates)
      dist abs
    } if_false: {
      0.0
    }
  end
end
 
chris = Person new: "Christopher Bertels" age: 22 city: "Osnabrück"
city = Place from_city: "Berlin"
 
Console puts: "Distance from chris to city:"
Console puts: (chris distance_to: city)
 
# Person mixed in ModuleA & ModuleB:
chris method_a
chris method_b

I’m still tweaking a little here and there, but I think most of the standard language features are working now. Now I’ll try to come up with some more unique things. I do have a few ideas already, but I still need to see, if they really work out nice. Let’s see ;)

Posted in General. Tagged with , , , , , , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.


Ihr Browser versucht gerade eine Seite aus dem sogenannten Internet auszudrucken. Das Internet ist ein weltweites Netzwerk von Computern, das den Menschen ganz neue Möglichkeiten der Kommunikation bietet.

Da Politiker im Regelfall von neuen Dingen nichts verstehen, halten wir es für notwendig, sie davor zu schützen. Dies ist im beidseitigen Interesse, da unnötige Angstzustände bei Ihnen verhindert werden, ebenso wie es uns vor profilierungs- und machtsüchtigen Politikern schützt.

Sollten Sie der Meinung sein, dass Sie diese Internetseite dennoch sehen sollten, so können Sie jederzeit durch normalen Gebrauch eines Internetbrowsers darauf zugreifen. Dazu sind aber minimale Computerkenntnisse erforderlich. Sollten Sie diese nicht haben, vergessen Sie einfach dieses Internet und lassen uns in Ruhe.

Die Umgehung dieser Ausdrucksperre ist nach §95a UrhG verboten.

Mehr Informationen unter www.politiker-stopp.de.