Mostrando entradas con la etiqueta lisp. Mostrar todas las entradas
Mostrando entradas con la etiqueta lisp. Mostrar todas las entradas

sábado, 1 de mayo de 2021

Wait a sec..., did I just ask for paredit-convolute-sexp?

So, After years of lisping, and using paredit (feeling that paredit is not for me, and realizing that "if paredit is not for you, you have to become the person who paredit is for", and becoming that person), I found a need for a command I wish it existed, and turns out it did.

After getting used to paredit, you just love it and miss it in non-lisps. But there is this paredit command that is basically a big question mark. You read about it when you were learning paredit, it didn't make sense then, and you moved on with your life, barfing, raising, and splicing sexps.

So it just clicked today, (now that I'm back to lisp (clojure)). I was thinking "there should be a way to do this", and then remembered there are a few paredit commands that I didn't find use for when I learned about them. And Bingo! It's just one of them!: paredit-convolute-sexp.

So the situation where it's useful is when you want to "swap" 2 "wrapping macros".  By "wrapping macros" I mean any macro or special form that expects a body. Such forms are "let", "binding", "with-redefs", "db/transaction"... you know, all those.

And by "swapping", I mean changing who wraps who. Here's a before/after 


See? Instead of a "let" wrapping a "binding", we get "binding" wrapping a "let".

If the binding forms (the pairs in square brackets) live in the same line as the special form function (like the previous example), and if you would be using evil, you would just swap the lines with ddp and reindent. 

But if the binding forms live in different lines, it's not as straightforward anymore.   I hope you know where I'm going now...

Well, paredit-convolute-sexp helps in those situations. Your only task is to put the cursor in inner expression, exactly in the place where you want the split to happen: before the first form that belongs to the &body. Then you press M-? (now, I think I even "see" why the shortcut). And magic happens.

The movement and the results are weird to explain, but with proper examples, it is easier to get a feel for it. Just try it in different positions with code with lots of nesting.

domingo, 21 de febrero de 2021

"When all you have is a Lisp ...

...everything looks like a recursive merge of trees"


It's been a little more than a month at Metabase, and doing Clojure is giving me again those deep recursive thoughts of seeing every problem as a recursive merge of trees.


I've looked at this python deep merge of dictionaries I used for some project at my previous $JOB.

And there are DSLs everywhere (sometimes, more than I think are needed).

And there's Specter, and Meander (https://www.reddit.com/r/Clojure/comments/loz77v/just_came_across_specter_mind_blown/ ) that use the code-is-data approach.

And just getting familiar with edn, that even it is very simple and minimal. It is malleable enough to be processed. 

I'm also working on a clojure version of gojira, that of course uses some tree merging.

miércoles, 28 de octubre de 2020

Some Tcl

Wanna spend an afternoon learning a scripting language that you didn't know about?

 

Tcl has appeared in HN recently a couple of times, and every time I read about it I remember that great article by antirez showing some very cool features of Tcl. So The link that appeared in HN today was a book by Hal Abelson and Philip Greenspun. 

 

In the intro, It's funny how they compare Tcl and Lisp.

 

Anyway, the links: 

  • http://antirez.com/articoli/tclmisunderstood.html
  • https://philip.greenspun.com/tcl/index.adp

miércoles, 6 de noviembre de 2019

SICP and Hal Abelson

So I got recently hooked up to SICP again, and binge watching the 80's classes in HP.

Also, rereading parts of the book and feeling that magic again.


Starting from there, I've researched a bit more from the authors, and I've focused in Hal Abelson.

Usual links:



sábado, 12 de mayo de 2018

Lisp recent threads

Lately, some articles on Lisp appeared in my usual websites.

Here's a HN thread where you can see the usual lispers enlightening other people about why Common Lisp is a very special beast.  DR Christian Shafmeister (CLASP) gives masterclasses in every post. Don't miss any :). There's some mention to those charts, where lisp shows as one of the both fastest and cheapest languages (after the ones that are specifically built to be superfast or efficient, while being more flexible than both)

Beautiful Racket, another hn post about the book.

Cloe lang. Apparently a heavily concurrent lisp.

extramaze, is built with racket, and the post shows some tricks used there.

Some CL macros?

Insightful post about starting a project in CL (going from repl to a project). Specially cool comment on tooling.

And as a bonus, RMS talking about his story with lisps. Very nice read also

I think I miss CL ... (...said while installing sbcl....)

viernes, 1 de septiembre de 2017

Birds of a feather lisp together

Now that I have some time in my hands (and I already mis Lisp), I'm watching several old Lisp talks, and stumbled upon This event.

On December 3 and 4 of 2004, the Computer Science Department at Indiana University hosted this conference on the occasion of Dan's sixtieth birthday.

Guy Steele's talk is great, as always. Nothing surprising there.  Talking about Dan's ideas and Dan itself (and giving a feeling about Dan being isomorphic to what Gilad Bracha says about Luca Cardelli here).

Gerald J Sussman's talk is also very nice, again, as usual.

And all talks I saw have that lispy emotion that we love.

But something that stroke me the most (that after reading 'The information' I realize more) was when Guy Steele talks about the time he read a draft of GEB. It's also a warm fuzzy feeling. Reading GEB leaves some trace in the reader forever. You never read a book the same way, or look at reality in the same way. Same happens with SICP (in process analysis).

Then I realized that in the picture of the event, there are the 3 of them. gls, gjs, and Douglas Hofstadter. Because obviously, they are "friends".  And the realization that the authors of my 2 favourite books ever hang around sometimes.

I also remember some Alan Kay talk where he says something like: "a few hours ago I found Guy Steele in a corridor in this event and we talked about blablabla.....". 100% natural :)

Then, while researching a bit for this post, I browsed wikipedia for Hofstadter. And another "proof" that "among certain level of smartness, there's just 1 degree of separation between any two people".

[...]he organized a larger symposium entitled "Spiritual Robots" at Stanford University, in which he moderated a panel consisting of Ray KurzweilHans MoravecKevin KellyRalph MerkleBill JoyFrank DrakeJohn Holland and John Koza

martes, 8 de agosto de 2017

Dynamic Languages Wizards Series - Panel on Language Design

This video is a stream of knowledge and insights capsules from VERY smart people related to dynamic languages. Give it a try. 0 bullshit.


miércoles, 8 de febrero de 2017

Henry G Baker's papers

I was rereading "Out of the tarpit" paper, and by the end of it I noticed they reference a paper from Henry Baker: "Equal rights for functional objects or, the more things change, the more they are the same.". The author's name rang a bell, and I decided to explore a bit more.

So, He's the author of a paper I loved to read 3 months ago or so: Pragmatic Parsing in Common Lisp.

The article is an adaptation of Val Schorre's META-II paper to common lisp, leveraging reader macros to create parsers in very few lines of code.

Reading a bit more, I found this other very enjoyable article: Metacircular Semantics for Common Lisp Special Forms . This one takes the approach of metacircular interpreters to explain the behaviour of some common lisp special forms in terms of other common lisp expressions.  I love the bottom up approach, and reminds me of "git from the bottom up", or CTMCP's explanations of the extensions to the Oz language.

He wrote lots of articles related to Lisp to different degrees, but most of them (the ones I skimmed) are written in a very clear language (no pun intended), and quite fun and enlightening reads.

lunes, 18 de julio de 2016

TIL: Remove a defined method (with defmethod) in Common Lisp

I created a defmethod for a more specialized class than the ones existed. and now I'd like to remove that method....

(remove-method #'foo (find-method #'foo '() (mapcar #'find-class '(class-of-first-specializer class-of-second-specializer))))

martes, 21 de junio de 2016

TIL: Toggle tracing defuns with slime


A nice and quick way to trace/untrace defuns from slime:

(define-key slime-mode-map (kbd "C-c t") 'slime-toggle-trace-fdefinition)

viernes, 19 de junio de 2015

Clasp. Implementation and its applications. Just wow

A talk that just left me shitting bricks. And makes me want to return to the drug discovery world via Common Lisp.

If you have any work for me, mail me at raimonster+nospam@gmail.com .

Wow Wow Wow.




And here's another neat story about lisp hackers: Crash Bandicoot in Lisp

jueves, 8 de mayo de 2014

Presenting Eva

I've hacked a tiny little lisp interpreter in lua, and I called Eva, for obvious reasons.

It's not pretty, it's not complete at all. Hell, it doesn't even have strings, you can't call native lua functions, and there are no conses (although you could get them using functions for that).

The whole point of it was to have some fun implementing a tiny lisp-like thingie, and to make it in lua, which is a language that I like quite a lot (although some of its table missfeatures make me cry sometimes)

Without further ado, Eva .

martes, 15 de mayo de 2012

Lisp debugging, step by step. Step 1

Debugging lisp is not as straightforward as one might think at first.  Being a live environment I thought it would be a joy, like in smalltalk, racket, or elisp, which provides a quite decent tracer and stepper.  Smalltalk is another world, but I'm already getting used to it so it doesn't surprise me that much.

We all heard stories about lisp machines (genera), and eventually read some article or seen some talk about how awesome it's lisp to debug.. but for me it was not so straightforward.

I'm using SBCL for all my experimentation in CL, so the examples here are going to be all sbcl related.  First of all, some reasons on why there's not an easy mapping between your debugger on the language next door and lisp when debugging:

- Lisp normally compiles the source code to native code. Doing so, it runs lots of optimizations on your source, so the code executed has no direct mapping to your written code.
- Lisp is not line oriented, so the order of execution of code is not so easily mappable to the typical next-line, next-line... debugging.
- On the other side, you have 'trace' that lets you track all executions of a function, with params, and so. It's not so live, but with all the instrumentation that sbcl and slime provide, you can track down a fair amount of bugs just with trace.

To instrument a method to be debuggable more easily, my advice is to add this declarations.

  (declare (optimize (speed 0) (space 1) (compilation-speed 0) (debug
3)))

That'll keep sbcl out from doing optimizations that can make variables 'disappear' in runtime.

A little more info in:

http://www.rhinocerus.net/forum/lang-lisp/583943-sbcl-line-line-debugging-tracing.html


and obviously, in your nearest implementation manual http://www.sbcl.org/manual/Debugger.html

domingo, 4 de marzo de 2012

more macros

Some links to useful/cool/smart lisp macros are appearing in that reddit post . There are a few really nice examples: from 'simple' templating systems to output html from Lisp, to more or less sophisticated macros-that-generate-macros, and even execute comments using reader macros. And the amazing factor-like stack concatenative language inside emacs (||| lisp-val: (list 1 2 3 4) { 1 + } map { 2 > } filter )

Here is a page where you can find most 'standard' macros from On lisp, ready to use for emacs lisp. I've used some of them for my new emacs project I'm doing with davazp.

There are also some nice macros in the third part of lisp for the web articles.

And here's a nice example of how awesome can 25 lines of lisp be. Not sure it's the best macro example, but got a smile in my face the first time I saw it.

sábado, 28 de enero de 2012

Lisp and the web (probably part 1)

I've tried some lisp frameworks with different intensities and approaches, without settling with anyone of those. Just looking around.

As a first approach, I'm going for the minimalist frameworks. Caveman (on top of Clack), and RESTAS.

My first experience is with caveman, as I want something really simple, and known. Not that I've worked with Sinatra/Rack nor Flask/WSGI, but at least, the architecture is more well known that with other fw like weblocks or RESTAS.

With Toni, we've been hacking a bit our way to do a super simple micro app. And we stumbled upon a few WTFs, or undocumented Caveman spots, or just blockers for us due to our lisp newbieness. Luckily, most of them are solved now :)
  • In GETs, (getf params :id) work, but in post POSTs, the symbols are presented in a different format (getf params :|id|). As davazp pointed, this probably has some problems issues with CL never garbage collecting those interned symbols.
  • clsql:*default-database*. clsql will use *default-database* database handler if you dont's specify any. This makes using clack's middleware for clsql transparent from caveman apps.
  • Getting caveman through quicklisp threw some erros during installation. Installing newer version of sbcl just solved it. (http://comments.gmane.org/gmane.lisp.steel-bank.announce/111)
     * new feature: SB-EXT:VALID-TYPE-SPECIFIER-P returns whether a given type
specifier is valid where "valid" basically means "would be accepted as
second argument of TYPEP".

  • cl-project doesn't create the link in ~/quickload/local-projects on new generated projects . If you create your projects under ~/quickload/local-projects, quicklisp will be able to quickload it, but if you put it somewhere else, you should create a link to your project.


I'm now struggling with form-builder, and widgets (no docs nor examples at all). We'll see how it goes.

viernes, 20 de enero de 2012

XML < JSON < SEXPS

Step by step, I keep getting more and more of what's lisp about.

Not just the syntax (huh?) or the core lib, but idioms, design decisions, and the vision.

One of the mottos of Lisp is the famous 'code is data, and data is code'.
For me, that's not 100% clear yet, but I get more insights every day.

One implication of this is when you look at s-exps and see them as a datastructure, not as code. That's the macro point of view. If you want to know more about macros, I can only recommend you Paul Graham's OnLisp, and Doug Hoyte's Let Over Lambda. I'm now reading through the latter and I find it a perfect companion for OnLisp.

The other direction is 'data is code'. To exemplify this side, here are a couple of links that really get to the point of this (at least one part of the point).

Cya

domingo, 20 de noviembre de 2011

Creating a simple common lisp application

After giving a further look at common lisp (a bit of PAIP, and PCL), I've found a project that can be a nice 1st app for me.

To develop a common lisp app, first you need to set up the environment and choose the toolchain. These have been my decisions. Tips are pretty appreciated.

Requirements

The requirements are the bare minimum for common lisp. I use SBCL myself, and don't know much of the differences between implementations. sbcl works just fine.

Editor

I use emacs 24, with slime, paredit and autocomplete. Use whatever you feel like but notepad. Obviously, emacs is recommended :)

Libs

Use quickload to find and load libraries. It's surprisingly easy and straightforward to use.

Project

quickproject to initialize the project is a nice way to avoid writting bolierplate, and to make sure your project will be loadable through ,load-system.

Tests

I tried a couple of testing packages for common lisp, and decided to go with lisp-unit due to its simplicity and availability in ql repos.

Code repository

The code is being hosted in a private git repo in bitbucket. They give you unlimited public/private (*yes*, private) repos, using git/hg, with issue tracking and all, for free. It seems a nice nice alternative to github. great to host projects in early stage where you don't feel like sharing the code to the world.

That's it for now. There's no public code for the moment... There's nothing to see here :)

domingo, 21 de agosto de 2011

Cellular automatas and me

2 weeks ago I started to read Philosophy and simulation by Manuel DeLanda (thanks eskerda).

About one month ago I watched jdelgado's talk at Campus Party talking about science in science fiction, and he talks a bit about cellular automata too:


So I started to experiment a bit with cellular automatas myself, and implemented a Conway game of life in smalltalk. At first I wanted to write a very flexible (1d,2d,...nd) cellular automata engine, but once I had the 2d Game of life implemented, I realized that doing 1d things is easier if you do it with strings, or just lists (lisp lists, for example).

Well, so I implemented a 1d cellular automata in common lisp (nice exercise) and tried some interesting rules for the majority problem jdelgado mentions in his talk.

At first I thought majority problem had a defined proper solution, but searching on the internetz, it seems it's not trivial at all, and I couldn't find anything that takes me further than rule 184, that splits the list in a group of 0's and 1's.

If you want the implementation of the smalltalk GoL, ask for it (it's not that easy to paste smalltalk code on the web, you know...), or just download any already existent implementations on squeaksource, like Bernat's one.

martes, 7 de junio de 2011

PAIP, special edition




I recently bought a copy of PAIP in dead tree format (as usual, a used one). When I received it, I was a little worried about the state of the book (it was expensive enough to be worried about it). I opened the package, glanced it and seemed pretty good. Nearly unused.

But when I opened it... OMG! The fist page contains a note from Peter Norvig!

FUCK YEAH!