Skip to content

Instantly share code, notes, and snippets.

View juan-reynoso's full-sized avatar
🏠
Working from home

Juan Reynoso juan-reynoso

🏠
Working from home
View GitHub Profile
;; list to string
CL-USER> (map 'string (lambda (x) (char (write-to-string x) 0)) '(1 2 3))
"123"
;; string to list
CL-USER> (map 'list (lambda (x) (intern (string-upcase (string x)))) "lisp")
(L I S P)

How to install and configure your IDE for Common Lisp

SBCL

SBCL is a high performance Common Lisp compiler.

http://www.sbcl.org/

SBCL installation as super user (root)

You need to run the commands as super user (root)

Download


@juan-reynoso
juan-reynoso / condition-handler.lisp
Created November 17, 2022 23:58
The basic form of a HANDLER-CASE
;;;; Condition Handler
;;;; The macro HANDLER-CASE establishes this kind of condition handler.
;;;; The basic form of a HANDLER-CASE is as follows:
;;;; (handler-case expression
;;;; error-clause*)
;;;; where each error-clause is of the following form:
;;;; (condition-type ([var]) code)
;;;; The Standard Method Combination
(defclass book ()
((name :accessor book-name
:initarg :book-name)))
;;; Create an object
(defparameter *book* (make-instance 'book
:book-name "The Art of the Metaobject Protocol"))
@juan-reynoso
juan-reynoso / lisps-sql.lisp
Last active June 22, 2022 22:55
Lisp s-sql with postmodern
(in-package #:pomo)
(defvar *db-spec* '("my_database" "my_user" "ultra-secret-password" "localhost" :POOLED-P T)
"Information about the connection of the database.")
(defmacro with-database-connection (&body query)
"The connection pooler.
This macro establish the connection with specified database in *db-parameter* variable and execute the QUERY.
IN: query that representing the users' query
OUT: result of the query"
@juan-reynoso
juan-reynoso / syntax-highlighting-for-the-web.html
Last active March 21, 2022 20:56
Example: Syntax highlighting for the Web
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Syntax highlighting for the Web</title>
<!-- highlight-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/styles/rainbow.min.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
(in-package :postmodern)
(defvar *db-parameters* '("my_database" "lisp_user" "your-secret" "localhost" :POOLED-P T)
"Information about the connection of database.")
(defparameter *my-fruit* nil
"This var will has an object of fruits.")
;;; Define the macro to connect to the postgresql server
(defmacro with-database (&body query)
@juan-reynoso
juan-reynoso / generic-functions.lisp
Created December 29, 2021 18:56
Generic functions
;;; A generic function specifies only the interface.
;;; It performs a high-level operation.
;;; Generic functions are functions that behave differently
;;; depending on the type and identity of the arguments.
(defgeneric say-type-of-object (x)
(:documentation "It displays the type of an object."))
;;; The implementation of a generic function does not exist in one place; it
;;; is distributed across a set of methods.
@juan-reynoso
juan-reynoso / copy-file.lisp
Created October 29, 2021 22:05
Creating streams on files
(defun copy-a-file (origin-path new-path)
"Copy a file"
(let ((value-from-read-byte nil))
;; create a stream which reads a file
(with-open-file (origin-file origin-path :direction :input
:element-type 'unsigned-byte)
;; create a stream which write into a file
(with-open-file (new-file new-path :direction :output
:element-type 'unsigned-byte
:if-exists :supersede)
@juan-reynoso
juan-reynoso / Lisp files.lisp
Created October 28, 2021 22:51
A file handling example
(defparameter *line* nil "This is a global variable")
;;; an example
(with-open-file (file "/tmp/myfile.txt" :direction :input)
(loop
;; gets a line from the file
(setf *line* (read-line file nil))
(if *line*
;; print the lines stored in the text file
(format t "~% ~a ~%" *line*)