https://github.com/stylewarning/parameterized-function
https://github.com/stylewarning/parameterized-function
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stylewarning/parameterized-function
- Owner: stylewarning
- License: bsd-3-clause
- Created: 2023-04-09T22:09:01.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-09T22:22:45.000Z (about 3 years ago)
- Last Synced: 2025-03-25T23:34:10.954Z (over 1 year ago)
- Language: Common Lisp
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
PARAMETERIZED-FUNCTION
======================
By Robert Smith
This package provides functions which can be parameterized, whose
parameters are dispatched at compile time.
Parameterized functions are defined by first declaring the "dispatch
function". For example, if we wanted a general multiply function that
gets dispatched at compile time, we might declare the following:
(define-dispatch-function mult (xtype ytype) (x y))
Next, we can define several parameterized functions.
(define-parameterized-function mult (:integer :integer) (x y)
(* x y))
(define-parameterized-function mult (:integer :string) (x y)
(with-output-to-string (s)
(loop :repeat x
:do (write-string y s))))
(define-parameterized-function mult (:string :integer) (y x)
(with-output-to-string (s)
(loop :repeat x
:do (write-string y s))))
(define-parameterized-function mult (:string :string) (x y)
(concatenate 'string x y)))
If we call MULT with a constant (quoted) list as the first argument,
then it will be expanded, at compile time, to one of the above
definitions. If the first argument is not constant, then dispatch will
occur at runtime.