Dagger Lang

Introduction

Main Documentation:


Working with Dagger
Dagger Values
User Input

Builtin Functions:


Lambda
Set
Put
List
Head
Tail
Eval
Join
Addition
Subtraction
Multiplication
Division
Modulo
Power
If
Equals
Not Equal
Greater Than
Less Than
Greater Than or Equal
Less Than or Equal
Read Integer
Read Decimal
Read String
Load
Error
Print

Builtin Put


The put function is extremely similar to the set function, with only one difference. As mentioned on the previous page, the set function creates a variable on the global environment (can be used anywhere), whereas the put function creates a variable in the local environment (can only be used in the current scope).

Use



    = {name} value

Examples


To help you better understand scope, we will write this code in an external file, saving it as put-example.dgr:


    (set {func} (\ {x} {
        (= {y} 12)
        (print (eval {+ y x}))
    }))

    (print (func 1))
    (print y)

First, we'll explain this chunk of code. We bind the symbol "func" to a lambda function that will do the following: 1) create a local variable called y, and 2) print y + x (it's basically the 'add twelve' function but with a variable. Then, outside of the function, we pass 1 to it, print it, then try to print y. Here's the output:


    13 
    Error: S-Expression starts with incorrect type. Got S-Expression, Expected Function.
    Error: Unbound Symbol 'y'

We see that the first print statement worked, printing 13. However, the second one gives us two errors, but we will pay attention to the second one only: 'Unbound Symbol y'. Because y is a local variable, we can only use it inside of the function, but we tried to access it from outside, thus returning an error.