Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Knut Olav Bøhmer
alexandria
Commits
d92432dd
Commit
d92432dd
authored
Dec 21, 2011
by
Ryan Davis
Committed by
Nikodemus Siivola
Jan 20, 2012
Browse files
convert ENSURE-GETHASH into a macro
Evaluate the default-form only if we actually use it.
parent
77b219a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
hash-tables.lisp
View file @
d92432dd
...
...
@@ -89,11 +89,11 @@ PLIST. Hash table is initialized using the HASH-TABLE-INITARGS."
(
setf
(
gethash
(
car
tail
)
table
)
(
cadr
tail
)))
table
))
(
def
un
ensure-gethash
(
key
hash-table
&optional
default
)
(
def
macro
ensure-gethash
(
key
hash-table
&optional
default
)
"Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT
under key before returning it. Secondary return value is true if key was
already in the table."
(
multiple-value-bind
(
value
ok
)
(
gethash
key
hash-table
)
(
if
ok
(
values
value
ok
)
(
values
(
setf
(
gethash
key
hash-table
)
default
)
nil
))))
`
(
multiple-value-bind
(
value
ok
)
(
gethash
,
key
,
hash-table
)
(
if
ok
(
values
value
ok
)
(
values
(
setf
(
gethash
,
key
,
hash-table
)
,
default
)
nil
))))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment