DEV Community

Vee Satayamas
Vee Satayamas

Posted on

6 4

Compile-time type checking in Common Lisp: a small experiment

In static1.lisp:

(defpackage static1 
 (:use #:cl)) 
(in-package :static1) 

(declaim (ftype (function (string string) string) concat-strings)) 
(defun concat-strings (a b)
  (format nil "~A --- ~A" a b)) 

(declaim (ftype (function (fixnum fixnum) string) concat-nums)) 
(defun concat-nums (a b)
  (concat-strings a b))
Enter fullscreen mode Exit fullscreen mode

Then I ran this command:

sbcl --noinform --eval '(compile-file "static1.lisp")' --quit
Enter fullscreen mode Exit fullscreen mode

SBCL showed this warning:

; caught WARNING: 
;  Derived type of STATIC1::A is 
;    (VALUES FIXNUM &OPTIONAL), 
;  conflicting with its asserted type 
;    STRING. 
;  See also: 
;    The SBCL Manual, Node "Handling of Types"
Enter fullscreen mode Exit fullscreen mode

So SBCL - a Common Lisp implementation, can check type in compile-time. Anyway, a programmer needs to read warnings.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up