about summary refs log blame commit diff stats
path: root/loot.lsp
blob: 857c7af7f56b927546b64c6d28041846725cd1ae (plain) (tree)
1
2
3
4
5
6
7
8
                                                                      
                              




                                                                      
                                                                 





                                                                


                                                                                                       
                                                                                                             













                               


                                                                  
                                                                      












































































                                                                                 
;;; Port of https://en.wikipedia.org/wiki/ModernPascal#Code_Sample[3].
;;; And then to CL and ISLisp.
;;; I prefer my version.
(defconstant +max-probability+ 1000)
;; Because this is a simple enum and not a full sum/product type,
;; I use symbols instead of CLOS.
(defconstant +loot-type+ (vector 'bloodstone 'copper 'emeraldite 'gold
                           'heronite 'platinum 'shaownite 'silver
                           'soranite 'umbrarite 'cobalt 'iron
                           'nothing))
(defclass <looter> () ((probabilities :accessor probabilities)))
(defgeneric choose (self))
(defmethod choose ((self <looter>))
  (let ((random-value (random (- +max-probability+ 1))))
    (for ((loop 0 (+ loop 1)))
	((>= (elt (probabilities self) (mod loop 13)) random-value) (elt +loot-type+ (mod loop 13))))))
(defmethod initialize-object :after ((self <looter>) initargs)
  (setf (probabilities self) (vector 10 77 105 125 142 159 172 200 201 202 216 282 +max-probability+  (case l
    ((bloodstone) "Bloodstone")
    ((copper) "Copper")
    ((emeraldite) "Emeraldite")
    ((gold) "Gold")
    ((heronite) "Heronite")
    ((platinum) "Platinum")
    ((shadownite) "Shadownite")
    ((silver) "Silver")
    ((soranite) "Soranite")
    ((umbrarite) "Umbrarite")
    ((cobalt) "Cobalt")
    ((iron) "Iron")
    (t "")))
(defun main ()
  (let ((loot (create (class <looter>)))    (for ((n 0 (+ n 1)))

                                                 	((> n 99))
	(format (standard-output) "~A~%" (as-string (choose loot))))))


. /usr/local/plan9/bin/9.rc
if (test -d /usr/local/bin) {
	path = (/usr/local/bin $path)
}
if (test -d /usr/local/opt/emacs-plus/bin) {
	path = ($path /usr/local/opt/emacs-plus/bin)
}
if (test -d $home/bin) {
	path = ($path $home/bin)
}
if (test -d $home/opt/GNAT/2020/bin) {
	path = ($home/opt/GNAT/2020/bin $path)
}

OPENLISP = $home/openlisp-11.0.0
if (test -d $OPENLISP) {
	path = ($path $OPENLISP)
}

# These break some commands like man.
# Use the new names instead.
#fn grep { rg $* }
#fn ls { exa $* }
#fn find { fd $* }
#fn cat { bat $* }
#fn more { bat $* }
#fn xterm { alacritty $* }

#prompt = ('$ ' '$ ')
REFER = $home/lsp/doc/refs

if (test -d $home/.cargo/bin) {
	path = ($home/.cargo/bin $path)
}

if (test -d /usr/local/opt/tcl-tk/bin) {
   path = (/usr/local/opt/tcl-tk/bin $path)
}

if (test -d $home/obnc/usr/local/bin) {
   path = ($path $home/obnc/usr/local/bin)
}

if (test -d $home/.emacs.d/bin) {
   path = ($path $home/.emacs.d/bin)
}
fn doom { u doom $* }
if (test -d /Applications/Emacs.app/Contents/MacOS/bin) {
   path = ($path /Applications/Emacs.app/Contents/MacOS/bin)
}
if (test -f /Applications/Emacs.app/Contents/MacOS/Emacs) {
   EMACS = /Applications/Emacs.app/Contents/MacOS/Emacs
   fn emacs { u $EMACS -nw $* }
}
if (test -f /Applications/Emacs.app/Contents/MacOS/bin/emacsclient) {
   fn emacsclient { u /Applications/Emacs.app/Contents/MacOS/bin/emacsclient $* }
}

LANG = en_IE.UTF-8
TZ = Europe/Dublin
LESS_IS_MORE = t
MORE = '-SEXIER'
POSIXLY_CORRECT = t
REFER = $home/lsp/doc/refs

if (test -d $home/context/tex/texmf-osx-64/bin) {
   path = ($path $home/context/tex/texmf-osx-64/bin)
}

if (test -d $home/Library/Python/3.8/bin) {
   path = ($path $home/Library/Python/3.8/bin)
}

TCLLIBPATH = $home/lib/tklib0.7