• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Noulakaz

Noulakaz

The blog of Avinash, Christina, Anya and Kyan Meetoo.

  • Home
  • About
  • People
    • Christina & Avinash Meetoo
    • Avinash Meetoo
    • Christina Meetoo
    • Anya Meetoo
    • Kyan Meetoo
  • General
    • News
    • Mauritius
    • Politics
    • Education
    • Business
    • Travel
  • Computing
    • Apple
    • Linux
    • LUGM
    • Programming
    • Web
    • Technology
    • Knowledge Seven
  • Entertainment
    • Music
    • Movies
    • Photography
    • Sports

Education

Factor, a practical stack language

15 January 2008 By Avinash Meetoo 1 Comment

I’ve just discovered Factor, a new programming language. It is a stack-based language like Forth and Postscript. Factor works on many different platforms.

I’m currently looking at it as one of the possible programming languages I’ll cover in my Programming Languages module at the University of Mauritius. Simple stack-based languages are interesting because they are low-level meaning that a student who understands Factor really understands how a computer works. And also the Java virtual machine which is also a stack-based bytecode interpreter.

Some example code

The Factor programming language is simple. For example,

10 20 30 + * .

displays 500. 10 20 and 30 are pushed onto the stack. + consumes the last two elements on that stack (20 and 30) and produces 50 which is pushed on the stack. * consumes the 50 and 10 and 500 is pushed. The . consumes one element of the stack (i.e. 500) and prints it on screen…

This morning, Pascal Grosset and I have been experimenting with different functions in Factor using the Factor workspace which is a great IDE. We have come up with the following:

: square ( x -- y ) dup * ;

This is a function called square that consumes one element of the stack (the x) and produces one element (the y). What it does is easy. dup duplicates the topmost element of the stack. * obviously multiplies the two topmost elements. That’s it.

: cube ( x -- y ) dup dup * * ;

Easy!

: big ( x -- y ) 10 > ;

big looks at the topmost element of the stack and replace it by t(rue) if it is bigger than 10 and (f)alse otherwise. t and f are Boolean values.

: negative ( x -- y ) 0 swap - ;

The swap is used to swap (what else?) the two topmost values on the stack. Notice that 0 is pushed before. And the – only does 0 – the number which was there already i.e. calculates the negative of that number.

: max ( x y -- z ) 2dup < [ swap drop ] [ drop ] if ;

What about this one? It contains a conditional statement (the if) which consumes three elements on the stack: a Boolean and two quotations (which are like Smalltalk and Ruby blocks which are evaluated later if needed). The first quotation [ swap drop ] will be evaluated if the condition is true and the second one [ drop ] otherwise. The 2dup function simply duplicates the two topmost elements on the stack. Get it?

Recursion in Factor

More complex Factor functions allow for recursion:

: fact ( x -- y ) dup 0 = [ drop 1 ] [ dup 1 - fact * ] if ;

Do you recognize our friend factorial? drop simply discards the topmost element of the stack. Notice that fact is called recursively until it hits the boundary case.

And finally,

: fib ( x -- y ) dup 1 <= [ drop 1 ] [ dup 1 - fib swap 2 - fib + ] if ;

This is another friend, the Fibonacci function. Have fun understanding it.

PS: Elie Chaftari says that according to Doug Coleman, one of Factor’s top gurus, you need to learn the following words (aka functions) by heart: dup, keep, 2dup, 2keep, swap, pick, rot, -rot, roll, -roll, 2apply, 2array, first2, nth, set-nth, append. Doug also advises to learn the following words for iterating: each, each-with, map, map-with, 2each, 2map.

Filed Under: Education, Programming, Technology

Learning part of CS does not make a CS?

5 December 2007 By Avinash Meetoo 15 Comments

I came across an interesting article called Should Java be banned from schools?.

The most interesting part were the comments. One of them rang a bell:

Also, no CS study is complete without some messing with machine level instructions, compilers & interpreters, algorithms, etc. Forget about learning a language: a good CS student must be able to design and build language + tool set from scratch. Here’s a CPU manual, go implement language foobar for it. Don’t come back until its compiler can bootstrap itself.

The problem is that many so-called universities don’t teach all this stuff. These second rate universities are popping up all over the world. They’re called universities but they are just processing mediocre programmers into cubicle occupying, php/Java/VB hacking zombies.

There is a lot of truth in that. Discuss.

PS: My favourite anti-Java article is The Perils of Java Schools – mind you, I like (and teach) Java…

PPS: The above image shown Emacs, my current Erlang IDE. I teach Erlang to my Concurrent Programming & Parallel Processing students.

Filed Under: Education, Programming, Technology

Functional programming to save the world

28 October 2007 By Avinash Meetoo 7 Comments

I’ve just come across an excellent article on eWeek titled Programming Superstars Eye Parallelism where some of the brightest computer scientists ever discuss on the Next Big Thing (TM).

James Gosling, creator of Java at Sun, Anders Hejlsberg, creator of Turbo Pascal at Borland and C# at Microsoft and Bertrand Meyer, creator of Eiffel reflect on “”What will you do with a 4,000-core machine?”

Multicore processors

Most of us buying computers now have dual-core processors like the Intel Core Duo I have on my MacBook. The same company has communicated on its Tera-Scale research program and has announced that 10-cores processors will be ready in two years. Intel is even experimenting with 80-cores processors…

Sun Microsystems already sells an 8-core processor with 4 hardware threads per core = 32 threads. It is, of course, the UltraSPARC T1 (Niagara) processor. It even has a successor called T2 which has 8 hardware threads per core i.e. 64 threads…

So the future is going to be massively multi-core.

The problem

Anders Hejlsberg says that “the models we have today for concurrency don’t work. Developers need to move an abstraction level up and he sees a resurgence of functional programming and its influences.” And the others agree.

Simply said, the way we program today (with C/C++/Java/C#/whatever) does not work on massively multi-core processors. This is because of state being shared among the cores and, hence, the necessity to use synchronization mechanisms a lot. The immediate consequence is that it becomes impossible to write programs which are free from deadlocks and starvation as the number of possible interleavings is massive. Exhaustive testing is impossible.

Functional programming to save the world

Joe Armstrong, the creator of Erlang, has spoken eloquently on why functional programming languages, which can be defined as languages without variables, are much more suitable to write concurrent (and parallel) applications than imperative languages that we all use today (like C/C++/Java/C#/etc)

Basically (and I quote),

    No Mutable Data Structures = No Locks = Easy to parallelize!

Incidentally, this is one of the reason I’m teaching Concurrency and Parallelism: I so deeply want functional programming to succeed!

I have been using Erlang for a month now to teach concurrent programming and, in my opinion, my students have loved it (and I too!)

Conclusion

The future is concurrent and parallel. And, according to the best, the future is also functional (very interesting things are happening in research, for example, F# and Data Parallel Haskell). Erlang is already here and is beautiful (and powerful).

I knew those hours I spent learning Scheme when I was younger were going to be useful.

I’m happy.

Filed Under: Education, Programming, Technology

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 43
  • Page 44
  • Page 45
  • Page 46
  • Page 47
  • Interim pages omitted …
  • Page 63
  • Go to Next Page »

Primary Sidebar

Our Personal Websites

Avinash Meetoo
Christina Meetoo
Anya Meetoo
Kyan Meetoo

Archives

  • June 2025 (1)
  • May 2025 (3)
  • April 2025 (4)
  • January 2025 (3)
  • December 2024 (2)
  • November 2024 (2)
  • October 2024 (3)
  • September 2024 (7)
  • August 2024 (1)
  • July 2024 (1)
  • June 2024 (2)
  • May 2024 (3)
  • January 2024 (2)
  • December 2023 (1)
  • October 2023 (1)
  • September 2023 (4)
  • August 2023 (3)
  • July 2023 (1)
  • June 2023 (4)
  • May 2023 (1)
  • April 2023 (1)
  • March 2023 (5)
  • February 2023 (1)
  • December 2022 (1)
  • November 2022 (1)
  • October 2022 (4)
  • August 2022 (4)
  • July 2022 (3)
  • June 2022 (5)
  • May 2022 (5)
  • January 2022 (3)
  • December 2021 (2)
  • November 2021 (1)
  • October 2021 (1)
  • September 2021 (4)
  • August 2021 (2)
  • July 2021 (14)
  • May 2021 (2)
  • April 2021 (4)
  • March 2021 (9)
  • February 2021 (2)
  • January 2021 (1)
  • October 2020 (1)
  • September 2020 (1)
  • August 2020 (2)
  • July 2020 (5)
  • June 2020 (3)
  • May 2020 (5)
  • April 2020 (6)
  • March 2020 (2)
  • February 2020 (2)
  • January 2020 (2)
  • October 2019 (1)
  • September 2019 (2)
  • July 2019 (2)
  • June 2019 (1)
  • May 2019 (3)
  • April 2019 (2)
  • March 2019 (1)
  • February 2019 (1)
  • January 2019 (3)
  • December 2018 (1)
  • October 2018 (3)
  • August 2018 (2)
  • July 2018 (2)
  • June 2018 (1)
  • May 2018 (2)
  • April 2018 (1)
  • February 2018 (1)
  • December 2017 (1)
  • October 2017 (1)
  • September 2017 (1)
  • August 2017 (1)
  • July 2017 (1)
  • May 2017 (4)
  • April 2017 (3)
  • March 2017 (4)
  • February 2017 (5)
  • January 2017 (3)
  • October 2016 (1)
  • September 2016 (1)
  • August 2016 (4)
  • July 2016 (1)
  • June 2016 (1)
  • March 2016 (3)
  • February 2016 (3)
  • January 2016 (1)
  • December 2015 (1)
  • November 2015 (2)
  • September 2015 (1)
  • August 2015 (3)
  • March 2015 (1)
  • December 2014 (1)
  • November 2014 (4)
  • October 2014 (1)
  • March 2014 (2)
  • February 2014 (3)
  • December 2013 (1)
  • October 2013 (1)
  • September 2013 (1)
  • August 2013 (1)
  • July 2013 (1)
  • June 2013 (2)
  • May 2013 (1)
  • March 2013 (3)
  • January 2013 (2)
  • December 2012 (3)
  • November 2012 (4)
  • September 2012 (3)
  • August 2012 (2)
  • July 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (2)
  • February 2012 (1)
  • January 2012 (4)
  • December 2011 (2)
  • November 2011 (1)
  • October 2011 (4)
  • September 2011 (2)
  • August 2011 (1)
  • July 2011 (2)
  • June 2011 (4)
  • April 2011 (7)
  • March 2011 (2)
  • February 2011 (1)
  • January 2011 (3)
  • November 2010 (3)
  • October 2010 (1)
  • September 2010 (2)
  • August 2010 (4)
  • July 2010 (2)
  • June 2010 (1)
  • May 2010 (3)
  • April 2010 (4)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (5)
  • December 2009 (2)
  • November 2009 (3)
  • October 2009 (1)
  • September 2009 (5)
  • August 2009 (3)
  • July 2009 (1)
  • June 2009 (3)
  • May 2009 (2)
  • April 2009 (7)
  • March 2009 (12)
  • February 2009 (10)
  • January 2009 (5)
  • December 2008 (4)
  • November 2008 (11)
  • October 2008 (6)
  • September 2008 (7)
  • August 2008 (3)
  • July 2008 (8)
  • June 2008 (6)
  • May 2008 (5)
  • April 2008 (7)
  • March 2008 (6)
  • February 2008 (3)
  • January 2008 (6)
  • December 2007 (11)
  • November 2007 (10)
  • October 2007 (7)
  • September 2007 (9)
  • August 2007 (3)
  • July 2007 (7)
  • June 2007 (8)
  • May 2007 (14)
  • April 2007 (11)
  • March 2007 (18)
  • February 2007 (14)
  • January 2007 (15)
  • December 2006 (16)
  • November 2006 (10)
  • October 2006 (7)
  • September 2006 (8)
  • August 2006 (8)
  • July 2006 (6)
  • June 2006 (4)
  • May 2006 (13)
  • April 2006 (10)
  • March 2006 (11)
  • February 2006 (7)
  • January 2006 (14)
  • December 2005 (8)
  • November 2005 (6)
  • October 2005 (7)
  • September 2005 (2)
  • August 2005 (6)
  • July 2005 (2)
  • June 2005 (6)
  • May 2005 (15)
  • April 2005 (12)
  • March 2005 (3)
  • February 2005 (8)
  • January 2005 (3)
  • December 2004 (1)
  • November 2004 (2)
  • October 2004 (2)
  • September 2004 (3)
  • August 2004 (3)
  • July 2004 (3)
  • June 2004 (3)
  • May 2004 (6)
  • April 2004 (10)
  • March 2004 (12)
Creative Commons License This work is licensed by Avinash Meetoo under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 Unported License.