Im looking for a way to extract all the elements of a list in common lisp. Like this
[194]> (break-out-of-list '(a b c d))
A
B
C
D
Edit: The usage example I gave was not thought out very well, however I'm still curious if it is possible to break out of a list like in the example above.
The methods are remove(), pop() and clear(). It helps to remove the very first given element matching from the list. The pop() method removes an element from the list based on the index given. The clear() method will remove all the elements present in the list.
You can convert the list to a set. A set cannot have duplicates. So if all the elements in the original list are identical, the set will have just one element. if len(set(input_list)) == 1: # input_list has all identical elements.
What you demonstrate seems to be the question how to get the elements of a list as multiple values:
CL-USER> (values 1 2 3)
1
2
3
CL-USER> (apply #'values '(1 2 3))
1
2
3
See also multiple-value-bind
and nth-value
in the hyperspec.
While (apply #'values '(1 2 3))
works there is also a function to this called values-list
which is used like this:
(values-list '(1 2 3))
And it has the same result.
Sure, just use apply
:
(defun wraptest (&rest arguments)
(apply #'test arguments))
This technically doesn't "break out of list"; it simply uses a list's elements as arguments to a function call.
(Disclaimer: I'm a Schemer, not a Common Lisper, and there may be a more-idiomatic way to achieve the same result in CL.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With