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)
@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)

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


;;;; 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"))
(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*)
@juan-reynoso
juan-reynoso / Object-Oriented-programming-example.py
Created October 13, 2021 15:54
Python Object-Oriented programming example.
# Python Object-Oriented programming
# Define a class called Dog
# Python class names are written in CapitalizedWords notation by convention.
class Dog:
# define a method called __init__ it is a special init method.
# "__init__" is a reseved method in python classes. It is known as a constructor in object oriented concepts.
# This method called when an object is created from the class and it allow the class to initialize the attributes of a class.
def __init__ (self, name, age):
# self represents the instance of the class. By using the "self" keyword. We can access the attibutes and methods of the
@juan-reynoso
juan-reynoso / JavaScript Objects.js
Created October 12, 2021 17:10
Creating a JavaScript Objects
/* Creates a single object, using an object literal.
* An object literal is a list of name:value pairs
(like age:36) inside curly braces {}.
*/
let myObjectPerson = { name: 'Juan', age: 36, sayHello: function (){
console.log("Hello, I am " + this.name + " and I am " +
this.age + " years old.");}
};