lispy | Code-as-data in Ruby , without the metaprogramming madness
kandi X-RAY | lispy Summary
kandi X-RAY | lispy Summary
Yeah, right. Get a room, you two.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of lispy
lispy Key Features
lispy Examples and Code Snippets
Community Discussions
Trending Discussions on lispy
QUESTION
Suppose we have a function with the following structure:
...ANSWER
Answered 2021-Apr-03 at 05:42A return
statement anywhere in a function is not functional.
In Python, you have no choice.
The Lisp code
QUESTION
A claim that I recall being repeated in the Clojure for Lisp Programmers videos is that a great weakness of the earlier Lisps, particularly Common Lisp, is that too much is married to the list structure of Lisps, particularly cons
cells. You can find one occurrence of this claim just at the 25 minute mark in the linked video, but I'm sure that I can remember hearing it elsewhere in the series. Importantly, at that same point in the video, we see this slide, showing us that Clojure has many other data structures than just the old school Lispy lists:
This troubles me. My knowledge of Lisp is quite limited, but I've always been told that a key element of its legendary metaprogrmmability is that everything - yes, everything - is a list and that this is what prevents the sort of errors that we get when trying to metaprogram other languages. Does this suggest that by adding new first-class data structures, Clojure has reduces its homoiconicity, thus making it more difficult to metaprogram than other Lisps, such as Common Lisp?
ANSWER
Answered 2021-Jan-18 at 20:34In Clojure, the only one of those extra data structures that is required for some language constructs, besides lists, are vectors, and those are in well-known places such as around sequences of arguments to a function, or in symbol/expression pairs of a let
. All of them can be used for data literals, but data literals are less often something you want to involve when writing a Clojure macro, as compared to function calls and macro invocations, which are always in lists.
I am not aware of anything in Clojure that makes writing macros more difficult than in Common Lisp, and there are a few features there distinct to Clojure that can make it a little bit easier, such as the behavior where Clojure backquoted expressions by default will namespace-qualify symbols, which is often what you want to prevent 'capturing' a name accidentally.
QUESTION
I'm trying to edit Norvig's lispy.py scheme-to-python interpreter for a racket program in which, in addition to the procedures he includes, I use open-input-string
and string-replace
.
It looked like I could just add the corresponding python definitions into his add_globals()
function, which I did, as follows.
ANSWER
Answered 2020-Nov-26 at 03:09It makes sense that you cannot find variable inputsliceexample
, because the variable you defined is named inputlistsliceexample
. So your string-replace
has worked fine. I'm not sure about your problem with open-input-string
, but from the link you posted it looks to me like read
takes in a file or a port or something like that, while your open-input-string
returns a string.
QUESTION
ANSWER
Answered 2020-Oct-29 at 15:42I would define an identity function and use it as a default parameter:
QUESTION
I have one more questions about Hygienic macros in Scheme, consider example from R5RS
...ANSWER
Answered 2020-Apr-13 at 21:42Yes. It is very non lispy that we have a modifier ...
that changes the meaning of element in front. eg. something ...
is basically similar to . something
except it works with structures like this:
QUESTION
Note to mods: Please note that this question is NOT AT ALL a question of taste. I am asking for specific information regarding the indenting conventions I have encountered in Spacemacs' default indentation rules for elisp.
Why is this code indented like this by formatters:
...ANSWER
Answered 2018-Mar-26 at 20:10Because the IF
operator of Emacs Lisp allows one then form and multiple else forms. The else forms are indented differently from the then form for readability.
QUESTION
I am self learning lisp and thought a nice non-trivial program would be to write a set of standard tree insertion and manipulation routines. I figured it could be done with CONS but wanted to try it with a structure.
I put together one version that worked:
...ANSWER
Answered 2019-Aug-15 at 06:48simple version for your inspiration:
QUESTION
I'm starting to work on some GUI programming and decided to use ltk. Ltk stands for "lisp toolkit" and it provides a lispy syntax layer over the basic tcl / tk commands. It's a lot like Tkinter for python in a way.
I've however found that, when putting two canvasses in one frame and having one of them expand in both directions. That canvas doesn't expand pas halfway point of the screen.
To show what I mean, I'll provide some pictures. Here's the window just after creation.
When expanded it looks like this:
I'm now trying to get rid of the light gray area, but whatever I do, the left canvas doesn't seem to want to enter the right half of the screen.
I'm running this on linux mint, but that shouldn't matter to much. And I'm using the ltk version released on 2-2-2019. I've tried messing with the current keyword arguments, but I've gotten nothing to work.
Here's the code that results in these screens.
...ANSWER
Answered 2019-Jul-23 at 11:07I sort of figured it out. I'm still not completely sure how tk works, but from this other answer I got the information to fix it.
Tcl/Tk: Frames misbehave when resizing.
It took a sligth translation, but removing the :expand
option for the right panel managed to solve the issue. The new code now looks like this:
QUESTION
Clojure has its own collections, and has no need of the traditional lispy cons cells. But I find the concept interesting, and it is used in some teaching materials (e.g., SICP). I have been wondering if there is any reasons that this cons primitive needs to be a primitive. Can't we just implement it (and the traditional functions that operate on it) in a library? I searched, but I found no such library already written.
...ANSWER
Answered 2018-Apr-23 at 15:12You could implement it yourself. Here is an attempt:
QUESTION
I'm trying to implement Unification, but having problems.. already got dozen of examples,but all they do is to muddy the water. I get more confused than enlightened :
http://www.cs.trincoll.edu/~ram/cpsc352/notes/unification.html
https://www.doc.ic.ac.uk/~sgc/teaching/pre2012/v231/lecture8.html [code below is based on this intro]
http://www.cs.bham.ac.uk/research/projects/poplog/paradigms_lectures/lecture20.html#representing
https://norvig.com/unify-bug.pdf
How can I implement the unification algorithm in a language like Java or C#?
The art of Prolog one ...and several others. The biggest problem is that I could not figure clear statement of the problem. More mathy or lispy explanations are confusing me even more.
As a good start it seems a good idea to follow the representation to be list based (like in the lispy cases) i.e. :
...ANSWER
Answered 2018-Mar-08 at 23:50I will quickly summarize the chapter about Unification Theory by Baader and Snyder from the Handbook of Automated Reasoning:
Terms are built from constants (starting with a lower case letter) and variables (starting with an upper case letter):
- a constant without arguments is a term: e.g.
car
- a constant with terms as arguments, a so called function application, is a term. e.g.
date(1,10,2000)
- a variable is a term, e.g.
Date
(variables never have arguments)
A substitution is a map assigning terms to variables. In the literature, this is often written as {f(Y)/X, g(X)/Y}
or with arrows {X→f(Y), Y→g(X)}
. Applying a substitution to a term replaces each variable by the corresponding term in the list. E.g. the substitution above applied to tuple(X,Y)
results in the term tuple(f(Y),g(X))
.
Given two terms s
and t
, a unifier is a substitution that makes s
and t
equal. E.g. if we apply the substitution {a/X, a/Y}
to the term date(X,1,2000)
, we get date(a,1,2000)
and if we apply it to date(Y,1,2000)
we also get date(a,1,2000)
. In other words, the (syntactic) equality date(X,1,2000) = date(Y,1,2000)
can be solved by applying the unifier {a/X,a/Y}
. Another, simpler unifier would be X/Y
. The simplest such unifier is called the most general unifier. For our purposes it's enough to know that we can restrict ourselves to the search of such a most general unifier and that, if it exists, it is unique (up to the names of some variables).
Mortelli and Montanari (see section 2.2. of the article and the references there) gave a set of rules to compute such a most general unifier, if it exists. The input is a set of term pairs (e.g. { f(X,b) = f(a,Y), X = Y } ) and the output is a most general unifier, if it exists or failure if it does not exist. In the example, the substitution {a/X, b/Y} would make the first pair equal (f(a,b) = f(a,b)
), but then the second pair would be different (a = b
is not true).
The algorithm nondeterministically picks one equality from the set and applies one of the following rules to it:
- Trivial: an equation
s = s
(orX=X
) is already equal and can be safely removed. - Decomposition: an equality
f(u,v) = f(s,t)
is replaced by the equalitiesu=s
andv=t
. - Symbol Clash: an equality
a=b
orf(X) = g(X)
terminates the process with failure. - Orient: an equality of the form
t=X
wheret
is not another variable is flipped toX=t
such that the variable is on the left side. - Occurs check: if the equation is of the form
X=t
,t
is notX
itself and ifX
occurs somewhere withint
, we fail. [1] - Variable elimination: of we have an equation
X=t
whereX
does not occur int
, we can apply the substitutiont/X
to all other problems.
When there is no rule left to apply, we end up with a set of equations {X=s, Y=t, ...}
that represents the substitution to apply.
Here are some more examples:
{f(a,X) = f(Y,b)}
is unifiable: decompose to get {a=Y, X=b} and flip to get {Y=a, X=b}{f(a,X,X) = f(a,a,b)}
is not unifiable: decompose to get {a=a,X=a, X=b}, eliminatea=a
by triviality, then eliminate the variableX
to get{a=b}
and fail with symbol clash{f(X,X) = f(Y,g(Y))}
is not unifiable: decompose to get{X=Y, X=g(Y)}
, eliminate the variableX
to get{Y=g(Y)}
, fail with occurs check
Even though the algorithm is non-deterministic (because we need to pick a equality to work on), the order does not matter. Because you can commit to any order, it is never necessary to undo your work and try a different equation instead. This technique is usually called backtracking and is necessary for the proof search in Prolog, but not for unification itself.
Now you're only left to pick a suitable data-structure for terms and substitutions and implement the algorithms for applying a substitution to a term as well as the rule based unification algorithm.
[1] If we try to solve X = f(X)
, we would see that X needs to be of the form f(Y)
to apply decomposition. That leads to solving the problem f(Y) = f(f(Y))
and subsequently Y = f(Y)
. Since the left hand side always has one application of f
less than the right hand side, they can not be equal as long we see a term as a finite structure.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lispy
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page