Hi Brian,

F# does not allow direct manipulation of an application stack like Forth. However there are some techniques that are quite similar between the languages.

Hope this helps,

Phil

Interactive Mode
Both Forth and F# have interactive modes that can be used for scripting.

Operators
In both Forth and F# operators can be used like functions:

  • Forth: 1 1 +
  • F#: (+) 1 1

Currying

Function parameters can be ommited:

  • Forth: : Inc ( n -- n ) 1 + ;
  • F#: let Inc = (+) 1

Passing left to right

F# defines a pipe forward operator (|>) as let inline (|>) x f = f x

  • Forth: 1 Inc
  • F#: 1 |> Inc

Recursion

Both F# and Forth support explicit recursive function definitions:

  • Forth: recursive keyword
  • F#: rec keyword

Sample

Putting all the techniques together in F# we can sum a list of integers like so:

1
2
3
4
5
6
7
let rec fold f acc = function   
    | [] -> acc    
    | x::xs -> fold f (f acc x) xs
 
let sum = fold (+) 0
 
[1;2;3] |> sum
By on 12/1/2009 12:40 AM ()

Hello Phil,

Thank you for that excellent reply to my question.

It's been years since I wrote anything in Forth; but there must have been enough residual experience to ring bells, as I began to look at F#.

For a largely forgotten programming language, I can say that I've been pleasantly surprised at the number of talented and accomplished people that still express appreciation for its qualities.

You've inspired me to go up into my attic and bring down my Forth books. Then I can go over the code examples you presented; and perhaps find a few more links.

In any case, your comparisons will help in my efforts with F#.

BRN..

By on 12/1/2009 2:09 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper