Comments (1)
For lists, it's definitely a stack - "last in first out" refers not to the ordering as you look at the data structure, but to the order in which elements are inserted and removed. So the last element to be inserted would be the first one to come back out.
Here's a lein repl
session with similar examples to that koan:
user=> (cons :a '(:b :c :d :e)) ;; adding :a to the *front* of the list
(:a :b :c :d :e)
user=> (conj '(:a :b :c :d) :e) ;; adding :e to the front using conj
(:e :a :b :c :d)
user=> (peek '(:a :b :c :d :e)) ;; "peeking" at the last element inserted, :a
:a
user=> (pop '(:a :b :c :d :e)) ;; removing the last element added, :a
(:b :c :d :e)
Basically, it's efficient to add elements to the front of a list, and it's efficient to remove elements from the front of a list. And adding & removing from the same end is what a stack does. With a queue ("first in first out"), we'd expect to add on one end, and remove from the other end.
"Insert" (or "add") and "remove" take on a little different meaning due to the immutability of the data structures, but hopefully this sheds some more light on why the list gets used like a stack!
from clojure-koans.
Related Issues (20)
- 13_creating_functions.clj (has a bug?) HOT 1
- Strict description of the rules HOT 2
- Problem with 15-destructuring.clj HOT 1
- 15_destructuring bug? HOT 3
- Can I translate koans? HOT 2
- Provide a way to run other 'sets' of koans HOT 2
- 24-macros / infix-better HOT 1
- 1.10 error messages break the koans HOT 3
- Not compatible with Clojure > 1.8 HOT 1
- Idea: hook this up as a jupyter notebook?
- Repl namespace issue HOT 1
- Koans for testing, Koans for agents HOT 2
- koans 19 datatypes, last meditation solution HOT 1
- Collection equality koan is confusing HOT 1
- 14 Recursion - is-even? HOT 1
- :refer :all HOT 4
- 24-macros contains two tests which can be made to pass with the same modification
- Unable to resolve symbol: hello in this context HOT 2
- the answer remains "AT&T Park".
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clojure-koans.