Call function in another lisp file

前端 未结 4 987
死守一世寂寞
死守一世寂寞 2021-01-15 17:26

I have to write a game in Lisp. In order to make it clear, I wanted to split the code in different .lisp files.

How can I call a function out of a function in the ot

4条回答
  •  心在旅途
    2021-01-15 18:06

    With Common Lisp I done it like this:

    In file1.lisp I define a function sayHello and export that function under the package name helloLisp

    (defpackage :helloLisp
        (:use :common-lisp)
        (:export #:sayHello))
    
    (in-package :helloLisp)
    
    (defun sayHello () (print "Hello!"))
    

    In the file file2.lisp I require this file like that:

    (require "helloLisp" "./file1.lisp")
    
    (helloLisp:sayHello)
    

    Tested with SBCL 1.4.11

提交回复
热议问题