How to implement a Stack in LISP language [closed] - stack

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am still learning Lisp language and I need to understand how to implement a stack with Lisp (Need push-pop-peek functions.). In addition I have found this code when I am searching for help. But I am not sure if it is working properly.
(defstruct stack
elements)
(defun stack-push (element stack)
(push element (stack-elements stack)))
(defun stack-pop (stack)(deftype Stack [elements])
(defun stack-empty (stack)
(endp (stack-elements stack)))
(defun stack-top (stack)
(first (stack-elements stack)))
(defun stack-peek (stack)
(stack-top stack))

Lisp lists are actually functional stacks in and of themselves.
(cons a l) pushes a to the stack l.
(car l) returns the first element (a peek).
(cdr l) returns all but the first element (a pop).

Related

How do I make unnumbered lists in Markdown? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to have this kind of lists:
asdasdas
aqweqwe
Instead of
asdasdasdas
jasdasdasda
Please help
Have a look at the Markdown syntax guide. In it's chapter about lists it says:
Unordered lists use asterisks, pluses, and hyphens — interchangably —
as list markers:
* Red
* Green
* Blue
is equivalent to:
+ Red
+ Green
+ Blue
and:
- Red
- Green
- Blue

How to break the line inside the brackets [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to be able to break the line inside the brackets without having the "inconsistant brackets" error.
Here's a example:
select.someclass.something{data: {max_amount: o.max_amount_clean, max_amount: o.min_amount_clean, fee: o.fee_clean}}
Thanks
I'm not sure if I understand, but if the argument is a hash and not a block, like it seems, you could do
select.someclass.something(
{data:
{max_amount: o.max_amount_clean,
max_amount: o.min_amount_clean,
fee: o.fee_clean}}
)

Sort an array/table of words from shortest to longest [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Corona/Lua how to sort a table of strings from shortest to longest
Assuming your table is a indexed table and not a keyed one try
test = {'123','1234','1245','1','12'}
table.sort(test, function(a,b) return #a<#b end)
for i,v in ipairs(test) do
print (i,v)
end
The important line here is
table.sort(test, function(a,b) return #a<#b end)
Words will only sorted by length and order within matching lengths will be arbitrary. If you want to sort by additional criteria, extend the function for the sort
eg function(a,b) return #a<#b end

Haskell: *** Exception: Prelude.read: no parse, Parsing, Read File [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am trying to read values from a .txt file and keep getting the above error. My code reads:
file <- readFile "films.txt"
let database = (read file :: [Film])
and Film is a data type I declared as:
type Film = (String, String, Int)
Still quite new to Haskell so have no idea how to parse a string back into the required type. Sort of assumed it would be nice and do it for me like it does with writeFile!
Any hints?

How to make text file (or other documents') parser? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have following task to do: to fill spell check dictionary (simple txt file) I need parser
which should: - parse within text file (or another type of document), extract
each word and then create text file with simple list of words like this:
adfadf
adfasdfa
adfasfdasdf
adsfadf
...
etc
What scripting language and library you would suggest? If possible, please, give example of code (especially for extracting each word). Thanks!
What you want is not a parser, but just a tokenizer. This can be done in any language with a bunch of regular expressions, but I do recommend Python with NLTK:
>>> from nltk.tokenize import word_tokenize
>>> word_tokenize('Hello, world!')
['Hello', ',', 'world', '!']
Generally, just about any NLP toolkit will include a tokenizer, so there's no need to reinvent the wheel; tokenizing isn't hard, but it involves writing a lot of heuristics to handle all the exceptions such as abbreviations, acronyms, etc.

Resources