Presentation could work (not really "done" though...)

This commit is contained in:
Erik Svedäng 2017-10-13 16:36:00 +02:00
parent 09fc80599a
commit 7fcb870c2b
3 changed files with 100 additions and 11 deletions

View File

@ -341,10 +341,100 @@ Double : Module = {
(deftype Point
[x Int
y Int])
Point : Module = {
init : (λ [Int Int] Point)
new : (λ [Int Int] (Ptr Point))
copy : (λ [(Ref Point)] Point)
delete : (λ [Point] ())
str : (λ [(Ref Point)] String)
x : (λ [(Ref Point)] Int)
y : (λ [(Ref Point)] Int)
set-x : (λ [Point Int] Point)
set-y : (λ [Point Int] Point)
update-x : (λ [Point (λ [Int] Int)] Point)
update-y : (λ [Point (λ [Int] Int)] Point)
}
```
---
# Allows structs to share member names
```
(deftype Vec2
[x Int
y Int])
(deftype Vec3
[x Int
y Int
z Int])
(let [v (Vec2.init 11 35)]
(Vec2.x &v))
(let [v (Vec3.init 300 400 500)]
(Vec3.set-y v 0))
```
---
# 5. Array processing
---
# Creating arrays
```
[1 2 3 4 5]
```
---
# [fit] Arrays can also be generated using various functions
```
Array.range : (λ [t t t] (Array t))
Array.repeat : (λ [Int (λ [] t)] (Array t))
Array.replicate : (λ [Int (Ref t)] (Array t))
```
Yes, the 't' in 'range' is too general.
---
# Mapping functions over arrays is useful
---
# Transforming from one type to another
Will allocate new memory and leave the old data as it was.
```
(let [xs [1 2 3 4 5]]
(transform Int.str &xs))
transform : (λ [(λ [a] b) (Ref (Array a))] (Array b)) ;; This type might be buggy!!!
```
---
# When mapping from one type to itself, the copying is unnecessary
```
(let [xs [1 2 3 4 5]]
(map square xs))
```
Ownership of 'xs' is passed to the map function, which will mutate the array and return it.
---
# Behind the scenes
---
# Written in Haskell
```
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Haskell 23 607 330 4350
-------------------------------------------------------------------------------
SUM: 23 607 330 4350
-------------------------------------------------------------------------------
```

View File

@ -4,6 +4,8 @@
* The 'range' function is fully generic (for all 'a') but only compiles when 'a' is numeric type
* Go over all the Array functions and make sure they are memory safe
* Can't define globals of type String or String-ref.
* Just entering '=' at the REPL leads ot strange type error.
* The lambda sent to 'transform' should probably have type (λ [(Ref a)] b) to prevent it from touching the contents of the source array
## Big Language Features
* Generic data types (apart from Array, which already is)
@ -13,6 +15,7 @@
## Smaller Language Features ("niceties")
* Good string functions
* Being able to use 'the' in function parameter declarations, i.e. (defn f [(the Int x)] x) to enforce a type
* Allow lambda ("λ") as an alias for Fn when defining types
## Language Design Considerations
* What's the correct type of the variable in a set!-form, i.e. (set! &x value) or (set! x value)

View File

@ -19,15 +19,11 @@
;; (print-stack &stack1)
;; )))
(defmodule Goods
(defn cost [] (random-between 100 200))
(def amount 75600))
(defn total-cost []
(* (Goods.cost) Goods.amount))
(defn main []
(println (refstr (total-cost))))
;; (defn main []
;; (println &Me.name))
(println
(ref
(Array.str
(ref
(let [xs [1 2 3 4 5]]
(transform Int.str &xs))
)))))