There are some ways.
Using mutables:

1
2
3
let mutable x = 100
x <- 10
printfn "%d" x

Note: mutables can't be used in inner functions

Using references:

1
2
3
let x = ref 100
x := 10
printfn "%d" !x

Note: you must apply dereference operator to access the value.

By on 2/27/2011 8:56 AM ()

Thanks for the reply

I have tried this

1
2
3
let setq a b =
    let a = b
    b

So it is the a that needs to be mutable?

By on 3/4/2011 1:32 AM ()

Can you please provide (and shortly explain) setq usage example. I can't figure out how it differs from an assignment operator in imperative languages.

By on 3/4/2011 3:05 PM ()

setq is basiclly the equivalent of a assignment operator.

I have not really messed with AutoLisp which is a variant of Lisp .

But as I understand it

AutoLISP evaluates everything including arguments in expressions

So (+ 2 4)

2 evaluates to 2

4 evaluates to 4

Then the + operator is applied to 2 and 4

setq is a combination of Set and Quote

Set assigns the value of the second argument to the value of the first argument.

The Quote function provides a means of preventing the evaluation of an argument

To set a variable to 1

(setq x 1)

Now to increment by 1

(setq x (+ x 1)) evaluates to

(set x 2)

if just set was used

(set x (+ x 1))

(set 1 2)----error

Lately I have been writing Apps for AutoCAD and its verticals and with the AutoCAD .NET API can do everthing and way more than in AuotLisp,

but since I was going to start learning F# I thought maybe I could use it to mimc the feel of AutoLisp to learn AutoLisp as I learned F#

Thanks for the reply

By on 3/5/2011 3:06 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