Skip to content

Instantly share code, notes, and snippets.

// time sortNumbers.js => 0.196
function randomInteger(lowerBound, upperBound) {
return lowerBound + Math.floor(Math.random() * (upperBound - lowerBound));
}
function* randomNumbers(count) {
for (var i=0; i < count; i++) {
yield randomInteger(1, 10);
}
}
// time sortNumbers.js => 0.196
function randomInteger(lowerBound, upperBound) {
return lowerBound + Math.floor(Math.random() * (upperBound - lowerBound));
}
function* randomNumbers(count) {
for (var i=0; i < count; i++) {
yield randomInteger(1, 10);
}
}
def parse_year_month(year_month):
return year_month.split("-")
def find_teams_that_disappeared_in_month(year_month):
current_year, current_month = parse_year_month(year_month)
if current_month == "01": # O is_january(current_month)
return frozenset()
previous_month = month_before(current_month)
current_teams = teams_in_month(current_month)
;; https://github.com/eudoxia0/crane/issues/51#issuecomment-184441942
(defpackage #:meta-helix-example
(:use #:cl #:c2mop)
(:import-from #:alexandria
#:if-let
#:when-let)
(:shadowing-import-from #:c2mop
#:standard-generic-function
#:defgeneric
#:defmethod)
; /home/puercopop/Projects/sbcl/obj/from-xc/src/pcl/walk.lisp-obj-tmp written
; compilation finished in 0:00:00.422
T
*
Likely suspicious calls:
113 MAPHASH
33 SB!DI::DESCRIPTOR-SAP
32 SB!C::LVAR-SINGLE-VALUE-P
13 SB!C::SET-BOUND
13 SB!KERNEL:BIG-RANDOM-CHUNK
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload '(trivia prove)))
(defpackage #:pdl
(:use #:cl #:trivia #:prove))
(in-package #:pdl)
;; Doesn't work for (x) case
(defmacro hb-let (vs &body forms)
@PuercoPop
PuercoPop / tweet-maze-general.lisp
Last active December 24, 2015 01:00
Solution for http://www.lispology.com/show?ZXE It takes advantage from the fact that when moving backwards there is only one possible move.
;; From: http://www.lispology.com/show?ZXE
;; A General solution
(defpackage #:tweet-maze
(:use #:cl))
(in-package #:tweet-maze)
(defun read-maze (string-description)
(loop :for index :from 0
:for char :across string-description
;; Rewrite add-all for clarity why mantaining the functional approach
(defun add-all (list)
(cond
((null list) 0)
((listp (car list)) (+ (add-all (car list)) (add-all (cdr list))))
((stringp (car list)) (+ (add-all (cdr list))))
(t (+ (car list) (add-all (cdr list))))))
;; First the ideal case

Ok so a while back a ran into a problem when extending the slot options in CLOS. I went digging in SBCL and saw it uses a case based approach to process the slot arguments/options. The AMOP in page 95 shows a way to use the CLOS famework to 'teach' CLOS how to process custom options (for slots and classes) inserting a generic function to hook into called 'canonicalized-{defclass,slot}-option'. However due to bootstraping issues IIUC (which I probably don't) defgeneric isn't avaiable at the time that code is evaluated so that extension can't be included willy nilly in SBCL itself.** So it occured to me that maybe a CLOS implemented on top the implementations CLOS could provide a path of least resistance to continue improving the CLOS framework*.

* I use framework not in the software sense but in the general sense.

** A possibl