Dabbling in Factor

Every once in a while I drag out some stack-based programming language, such as Forth. For some reason, there’s a soft spot in my heart for stack languages. The latest one I’ve been experimenting with is Factor.

My first words in Factor:

: square ( x -- x-squared ) dup * ;
: circle-area (r -- area ) square pi * ;
: hypotenuse ( a b -- c ) square swap square + sqrt ;
: distance ( x1 x2 y1 y2 -- dist ) rot - rot rot - hypotenuse ;
: gcd ( a b -- c ) dup 0 = [ drop ] [ dup rot swap mod gcd ] if ;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s