Author Topic: Flisp?  (Read 2709 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Flisp?
« on: March 04, 2011, 06:43:46 AM »
Was thinking and the best person to probably know how well it would work would be gile.

But I started to mess around and used F# to try to make it  look and feel like AutoLisp.

Defining functions

Code: [Select]

let setq a b =
    let a = b
    a 

let getpoint (prompt:string) =
    let doc = Application.DocumentManager.MdiActiveDocument
    let db = doc.Database
    let ed = doc.Editor
    let pnt = ed.GetPoint(prompt)
    pnt.Value

let car lst =
    match lst with   
    |[_] -> Some(lst.Head)
    |hd :: tail -> Some(hd)
    |[] -> None

let cdr lst =
    match lst with
    |hd :: tail -> Some(tail)         
    |_ -> None

or more like lisp returning a list
Code: [Select]
let getpoint (prompt:string) =
    let doc = Application.DocumentManager.MdiActiveDocument
    let db = doc.Database
    let ed = doc.Editor
    let pnt = ed.GetPoint(prompt)
    [pnt.Value.X; pnt.Value.Y; pnt.Value.Z]

but when the functions are used to look like Lisp but all .NET

Code: [Select]
setq pnt (getpoint "pick point")

I thought I could get more familiar with F# and learn Lisp at the same time.

Was wondering if anyone had ideas or input.



gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Flisp?
« Reply #1 on: March 04, 2011, 04:43:59 PM »
Hi,

Maybe a good way for those who knows F# and want to learn LISP, but, excepted 'functional programing style' LISP and F# are so different (mostly dynamic typing vs strong typing).

By my side I try, in the reverse way, to implement some F# List functions which don't exist in AutoLISP here.
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Flisp?
« Reply #2 on: March 04, 2011, 07:57:22 PM »
Some more here.
« Last Edit: March 05, 2011, 05:15:46 PM by gile »
Speaking English as a French Frog

hermanm

  • Guest
Re: Flisp?
« Reply #3 on: March 18, 2011, 11:39:28 PM »
car & cdr are built-in:

Code: [Select]
> let foo = [1;2;3;4];;
val foo : int list = [1; 2; 3; 4]

> List.head foo;;
val it : int = 1

> List.tail foo;;
val it : int list = [2; 3; 4]

(you can also use the older (ML) names, i.e., List.hd and List.tl)

so are cons, append, foreach & mapcar:

Code: [Select]
> 25::foo;;
val it : int list = [25; 1; 2; 3; 4]
> foo @ [12];;
val it : int list = [1; 2; 3; 4; 12]
> List.append foo [12];;
val it : int list = [1; 2; 3; 4; 12]


más por la manaña...