CLisp: Collecting all keywords supported - lisp

I tend to use Notepad++ as editor to learn lisp and this helps me with prompting the keywords as I type them on editor. But not all the keywords are enlisted in its language plugin.
I want to add those keywords into it. Is there some command in lisp that it lists its keywords or some source that contains these keywords/function templates etc that I can just add them by pasting them in NP++ plugin.
Manually accomplishing this will be very time consuming.

Assuming, that you want the symbols of the COMMON-LISP package, you can use
(do-external-symbols (sym :common-lisp)
(print sym))
to collect all symbols exposed by the COMMON-LISP package. According to the ANSI standard,
The COMMON-LISP package has as external symbols those symbols enumerated in the figures in Section 1.9 (Symbols in the COMMON-LISP Package), and no others"
so the above should give you exactly the stuff defined by the ANSI common lisp language (and nothing else).
To get a sorted list, try
(let (result)
(do-external-symbols (sym :common-lisp)
(push sym result))
(sort result #'string<))
on the REPL.

Perhaps you can just copy-paste the symbols from CLHS: http://www.lispworks.com/documentation/HyperSpec/Front/X_AllSym.htm

Related

Racket reader where newline is end of statement

I'm trying to create a new language in Racket where statements are on separate lines. A newline defines the end of a statement and the start of a new one.
I read through the Create Languages chapter of the guide which was very useful but the examples were focused on extending s-exp-like languages. The only option I see is manually writing my own parser for read and read-syntax.
I was hoping to use readtables but I don't know if I can. I tried:
(make-readtable #f #f 'non-terminating-macro my-read-line-fn)
but I don't know if this is much help. I guess I could create a sub-readtable that does things like read-word, read-string which I dispatch to based on what character my-read-line-fn gets.
Is that the best strategy or is there a predefined way of reading until the end of line?
I don't think you need to do anything with the readtable. Your lang/reader.rkt can provide your own read-syntax that can read/parse however it wants, and presumably stop when it encounters EOL.
One interesting example is Brainfudge. Its concept of a "statement" is a single character, but IIUC also [ brackets ].
See its lang/reader.rkt and parser.rkt for the low-level bits, and then try to understand how that is ultimately evaluated as Racket expressions.
You do indeed need to write version of read and read-syntax that parse your language. The readtable is only meant to modify the builtin read, so I suggest that you take a look at Parser Tools (http://docs.racket-lang.org/parser-tools/index.html), which is tool for writing parsers in the lex/yacc style.
An alternative is to use ragg:
http://www.hashcollision.org/ragg/
Install Ragg using the package manager in DrRacket. Search for ragg in the list of available packages.
Make your own reader.rkt:
#lang s-exp syntax/module-reader
(test test)
#:read-syntax my-read-syntax
#:read my-read
;; override default read (won't be used but is required)
(define (my-read in) (read-line in))
;; override read-syntax by reading in one string at a time and
;; pass it to statement-string->code to get code as dara and
;; make it syntax with datum->syntax
(define (my-read-syntax in)
(datum->syntax #f (statement-string->code (read-line in))))
;; This is actually how you want your code
;; to become s-expressions. I imagine that my
;; module has a primitive called code that
;; interprets the string as is
(define (statement-string->code str)
(list 'code str))
Racket doesn't have "statements", so the concept of newlines ending "statements" is nonsensical.
If your motivation is to reduce or do away with parentheses, I encourage you to use a "standard alternative" reader like sweet-expressions, rather than making something home-grown.

Why am I getting an unbound error for "atom?"

I'm trying to go through "The Little Lisper" and already running into snags in the first chapter. I'm relatively new to Emacs (which has fueled my interest in learning Lisp and clojure). I downloaded the Mit-scheme app, and am working the exercises on Edwin.
I'm trying:
(atom? (cons a l))
where a is an atom and l is a list already defined. I get the following error:
;Unbound variable: atom?
Why? I have no problems using the "null?" function. I thought "atom?" is an internal function checking to see if the value returned is an atom.
Any explanation would be much appreciated. I still haven't set up my emacs to run scheme, and the minor differences between all the lisp dialects is testing my patience.
In "The Little Schemer" ("The Little Lisper"'s updated version) the atom? procedure is defined as follows (because atom? doesn't exist in Scheme):
(define (atom? x)
(and (not (null? x))
(not (pair? x))))
If you're following an old version of the book, I advise you to either look for a newer version or use the same programming language used in the book: Common Lisp for The Little Lisper, Scheme for The Little Schemer - and Racket is a great Scheme IDE to work with! take a look at this answer for some tips when going through The Little Schemer using Racket.
I'm trying to go through "The Little Lisper"...
I downloaded the Mit-scheme
Common Lisp and Scheme are very different languages.
You have to either use a different book (e.g., SICP) to match your language implementation or a different language implementation (e.g., clisp or sbcl) to match your book.
Take a look at the Scheme R5RS specification; it includes a list of functions and syntactic keywords. Although not part of the Scheme standard, mit-scheme has a function apropos that will find functions (other stuff) with a given name. try:
(apropos "atom")
(but it won't show anything, :-).
An atom is something that is not a 'cons cell' (generally, if I remember my CommonLisp). In Scheme you could implement one as:
(define (atom? thing) (not (pair? thing)))
Note: this definition of atom? is consistent with CommonLisp atom.

Common Lisp fuzzy-searchable function reference?

Is there a nice and friendly set of searchable documentation for ANSI Common Lisp anywhere? Preferably one that can be downloaded for use offline. I've Google but can only find static HTML pages that basically mean you need to know exactly what you're looking for.
I'm after something like http://erldocs.com/, where I can type something like "string" or "list" and all the matching functions come up instantly, for me to click on and browse easily.
Man pages are no use, since you need to know the exact function you need, while the searchable style allows you to discover functions without knowing them beforehand.
CLHS: Symbol Index
l1sp.org
In Slime, type C-cC-dh, a few chars of your search term, and then Tab to get a completion list.
Just type (apropos "term") in repl.
A downloadable version of the CLHS is available in info format:
ftp://gnu.org/gnu/gcl/gcl.info.tgz
Here's a handy emacs function to lookup the symbol under the point in the using F1:
(defun clhs-info ()
(interactive)
(ignore-errors
(info (concatenate 'string "(gcl) " (thing-at-point 'symbol)))))
(add-hook 'lisp-mode-hook
(lambda ()
(define-key lisp-mode-map [f1] 'clhs-info)))
You can do partial matching using Info-index rather than concatenation as well.

Emacs Rename Variable

How do I rename a variable in emacs? Eclipse has a neat "rename" refactoring action which lets you rename a variable in a scoping-aware way, which can be much easier to use than doing localized replace-strings, especially if the variable name is a character like e. Does emacs have a similar functionality built in?
New Emacs has M-s . to select symbol under cursor, then you can C-M-% and it will use currently selected symbol to perform replacements. NOTE This is just plain string replacement, not like the IDE 'rename variable' feature.
iedit was made for this kind of thing.
You can use narrowing to only show part of a buffer, and search/replace will only operate in the narrowed region. For example, you could use C-x n d to narrow to the current function, or select the region you want and do C-x n n. Do your search/replace, then widen back with C-x n w. For a single letter variable like e, do a query-replace-regexp with C-M-% and use a regexp like \be\b so it will only work on individual e's instead of ones inside other words.
Edit: Just thought of another thing. If you select a region, search/replace only works in that area. So you could just select the scope you want to replace in, then do the query-replace-regexp thing.
With the advent of LSP support in Emacs the actual "rename" refactorings are finally becoming viable in addition to narrowing/iedit/multicursor etc options in other answers, dependent on what the underlying language servers support.
emacs-lsp package provides lsp-rename
eglot package provides eglot-rename
In Python, this is more or less doable with the Rope refactoring library, for which IĀ advise to use emacs-traad, in MELPA (straightforward to install and easy to use).
After installation we have the function M-x traad-rename which renames a variable in the project.
Rope documentation
For simpler search&replace, we have the aforementioned Iedit and also Projectile's projectile-replace.
I'm not sure what your source code language is. Because you mentioned about Eclipse, I assume that it is Java. One option is to use tags-query-replace functionality. Use Excuberant Ctags with -e switch to generate etgas style tags and invoke tags-query-replace.
Since you asked for a Eclipse feature, Iedit wont cut it. Its not that smart, what if you got two variables with the same name on different scopes? It would change both of them. This does not happen on eclipse!
You will need language specific tool if you expect that kind of awareness.
With typescript you can use tide.
With golang you can use go-doctor.
Specifically with Java, I could not find anything, but I use meghanada, which is great. But refactoring is on its TODO list! You use also use emacs as a client for eclipse with eclim.
As well as considering the already-suggested iedit, you can also consider multiple-cursors package. Check out an article about it, with animation of the live edition.
(defun replace-var (new)
"Replace the variable on the cursor"
(interactive (list
(read-string (format "Rename %s to: " (thing-at-point 'symbol)))))
(let ((old (thing-at-point 'symbol)))
(mark-defun)
(replace-string old new)))
(defun replace-old-var (old new)
"Input the old and new name"
(interactive "sFrom: \nsTo: ")
(mark-defun)
(replace-string old new))
(global-set-key (kbd "C-c r o") 'replace-old-var)
(global-set-key (kbd "C-c r v") 'replace-var)

print symbols of emacs in elisp

How to print all the symbols in emacs using elisp.
It is possible to test wheather a lisp object is a symbol using symbolp
function. But how to collect all the symbols.
Is it possible to access symbol table of emacs?
Here's one way to do it:
(require 'cl)
(loop for x being the symbols
if (boundp x)
collect (symbol-name x))
loop is a Common Lisp macro, that has been ported to Emacs Lisp as well. It's part of the cl package (part of the standard Emacs distribution), that you'll have to require to use it.
Another option to consider is probably:
(apropos "." t)
The apropos invokation will take significantly more time to complete, but you'll get more information about the symbols that way.
Just for completeness, here's how you'd list all of the symbols without using the cl package:
Go to a newly-created buffer, and type M-:(mapatoms (lambda (s) (insert (symbol-name s) "\n")))RET. That will insert the names of all existing symbols in the buffer, one per line.