this post was submitted on 27 Nov 2023
1 points (100.0% liked)

Lisp

53 readers
3 users here now

founded 1 year ago
MODERATORS
 

I would appreciate it if you could teach me about type inference in Lisp. Type Inference in Lisp. Weaknesses of Dynamically Typed… | by Kenichi Sasagawa | Oct, 2023 | Medium

you are viewing a single comment's thread
view the rest of the comments
[–] Frere_de_la_Quote@alien.top 1 points 11 months ago

This is a very complex problem. Maybe this will have some interest for you:

https://github.com/naver/lispe/wiki/6.1-Pattern-Functions

Here is how fizzbuzz is implemented:

; check if the rest of v/d is 0
(defun checkmod (v d) (eq (% v d) 0))

; if the element can be divided by 15 we return fizzbuzz
(defpat fizzbuzz ( [integer_ (not (% x 15))] ) 'fizzbuzz)

; if the element can be divided by 3 we return fizz
(defpat fizzbuzz ( [integer_ (checkmod x 3)] ) 'fizz)

; if the element can be divided by 5 we return buzz
(defpat fizzbuzz ( [integer_ (checkmod x 5)] ) 'buzz)

; rollback function, no type, we return x
; This function will only be called, if none of the above did apply
(defpat fizzbuzz (x) x)

; we apply 'fizzbuzz' to the first 100 elements.
; The argument type is: integer_

(mapcar 'fizzbuzz (range 1 100 1))