From 4c84db1504ee3c9cf9c98a93c58b6b5002534a75 Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 16 Aug 2007 14:21:37 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- code_examples/demo.scm | 95 +++++++++++++++++++++--------------------- mode/lisp.py | 5 ++- mode/scheme.py | 3 +- tab2.py | 3 +- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/code_examples/demo.scm b/code_examples/demo.scm index d46d193..54e5298 100644 --- a/code_examples/demo.scm +++ b/code_examples/demo.scm @@ -1,71 +1,72 @@ ; a helper function which prints each argument seperated by a space (define output - (lambda (. things) - (cond - ((null? things) (display #\newline)) - (else - (display (car things)) - (display #\space) - (apply output (cdr things)))))) + (lambda (. things) + (cond + ((null? things) (display #\newline)) + (else + (display (car things)) + (display #\space) + (apply output (cdr things)))))) ; a helper function which shows arguments before calling them (define explicit-apply - (lambda (f . args) - (let ((result (apply f args))) - (output f args result) - result))) + (lambda (f . args) + (let ((result (apply f args))) + (output f args result) + result))) ; determine whether or not a given attack roll will hit (define is-hit? - (lambda (roll attack ac) - (or (= roll 20) (and (< 1 roll) (>= (+ roll attack) ac))))) + (lambda (roll attack ac) + (or (= roll 20) (and (< 1 roll) (>= (+ roll attack) ac))))) ; determine whether or not a given attack roll will crit (define is-crit? - (lambda (roll attack ac threat) - (or (= roll 20) (and (is-hit? roll attack ac) (>= roll threat))))) + (lambda (roll attack ac threat) + (or (= roll 20) (and (is-hit? roll attack ac) (>= roll threat))))) ; determine the expected damage of a particular attack roll (define roll-dmg - (lambda (roll attack ac dmg threat mult) - (cond - ((is-crit? roll attack ac threat) (* dmg mult)) - ((is-hit? roll attack ac) dmg) - (else 0)))) + (lambda (roll attack ac dmg threat mult) + (cond + ((is-crit? roll attack ac threat) (* dmg mult)) + ((is-hit? roll attack ac) dmg) + (else 0)))) ; determine the expected damage across all attack rolls (define expected-dmg - (lambda (. args) - (define adder - (lambda (total roll) - (if (> roll 20) - total - (adder (+ total (apply roll-dmg roll args)) (+ roll 1))))) - (/ (adder 0 1) 20))) + (lambda (. args) + (define adder + (lambda (total roll) + (if (> roll 20) + total + (adder (+ total (apply roll-dmg roll args)) + (+ roll 1))))) + (/ (adder 0 1) 20))) ; find the best power attack score (and expected damage) versus an AC (define find-best-power - (lambda (power-max attack ac dmg threat mult) - (define checker - (lambda (power best-power best-dmg) - (if (> power power-max) - (list best-power best-dmg) - (let* ((a (- attack power)) - (d (+ dmg power)) - (ed (expected-dmg a ac d threat mult))) - (if (> ed best-dmg) - (checker (+ power 1) power ed) - (checker (+ power 1) best-power best-dmg)))))) - (checker 0 0 0))) + (lambda (power-max attack ac dmg threat mult) + (define checker + (lambda (power best-power best-dmg) + (if (> power power-max) + (list best-power best-dmg) + (let* ((a (- attack power)) + (d (+ dmg power)) + (ed (expected-dmg a ac d threat mult))) + (if (> ed best-dmg) + (checker (+ power 1) power ed) + (checker (+ power 1) best-power best-dmg)))))) + (checker 0 0 0))) ; iterate across a range of armor classes (define iter - (let ((max-power 6) - (attack 6) - (dmg 5.5) - (threat 20) - (mult 3)) - (lambda (ac max-ac) - (explicit-apply find-best-power max-power attack ac dmg threat mult) - (if (> ac max-ac) #f (iter (+ ac 1) max-ac))))) + (let ((max-power 6) + (attack 6) + (dmg 5.5) + (threat 20) + (mult 3)) + (lambda (ac max-ac) + (explicit-apply find-best-power max-power attack ac dmg threat mult) + (if (> ac max-ac) #f (iter (+ ac 1) max-ac))))) (iter 10 30) diff --git a/mode/lisp.py b/mode/lisp.py index 9b47dfe..da4bb1b 100644 --- a/mode/lisp.py +++ b/mode/lisp.py @@ -24,20 +24,21 @@ class LispTabber(tab2.StackTabber): if rtoken is not None and rtoken.string != '(': rtoken = self.get_next_right_token(y, i + 1) if rtoken is None: - level = self.get_curr_level() + 4 + level = self.get_curr_level() + self.mode.tabwidth else: level = rtoken.x self._append(token.string, level) return currlvl class Lisp(mode2.Fundamental): + tabwidth = 2 tabbercls = LispTabber grammar = LispGrammar opentokens = ('delimiter',) opentags = {'(': ')'} closetokens = ('delimiter',) closetags = {')': '('} - colors = { + colors = { 'comment': ('red', 'default'), 'string.start': ('green', 'default'), 'string.null': ('green', 'default'), diff --git a/mode/scheme.py b/mode/scheme.py index e007ecf..b92229a 100644 --- a/mode/scheme.py +++ b/mode/scheme.py @@ -26,13 +26,14 @@ class SchemeGrammar(Grammar): ] class Scheme(mode2.Fundamental): + tabwidth = 2 tabbercls = mode.lisp.LispTabber grammar = SchemeGrammar opentokens = ('delimiter',) opentags = {'(': ')'} closetokens = ('delimiter',) closetags = {')': '('} - colors = { + colors = { 'comment': ('red', 'default'), 'keyword': ('cyan', 'default'), diff --git a/tab2.py b/tab2.py index dbaf384..089a431 100644 --- a/tab2.py +++ b/tab2.py @@ -154,7 +154,8 @@ class StackTabber(Tabber): token = self.get_token(y, i) rtoken = self.get_next_right_token(y, i) if rtoken is None: - level = self.get_curr_level() + 4 + #level = self.get_curr_level() + 4 + level = self.get_curr_level() + self.mode.tabwidth else: level = rtoken.x self._append(token.string, level)