* how to turn off cl warning
@ 2012-12-15 9:15 Ivan Kanis
2012-12-15 9:22 ` Bastien
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Ivan Kanis @ 2012-12-15 9:15 UTC (permalink / raw)
To: emacs devel
[-- Attachment #1: Type: text/plain, Size: 406 bytes --]
Hi,
When I compile my program I get the following warnings:
In wpuzzle-format-game-over:
wpuzzle.el:185:46:Warning: function `coerce' from cl package called at runtime
I want to use coerce, how do I turn off the warning. I have attached the
file I am compiling.
--
Ivan Kanis
http://ivan.kanis.fr
Farewell, Love, and all thy laws forever.
Thy baited hooks shall tangle me no more.
-- Thomas Wyatt
[-- Attachment #2: wpuzzle.el --]
[-- Type: application/emacs-lisp, Size: 13533 bytes --]
;; -*- coding: utf-8; lexical-binding: t -*-
;;; wpuzzle.el --- find as many word in a given time
;;; Commentary:
;; Version 2.0
;; Version 1 was called 100secwp.el, I rewrote everything since.
;; Ideas for improvement:
;; - add other languages such as french
;; - input letter one by one like the original game
;; - really stop after 100 seconds
;; - display something more fancy with letter points (SVG would be cool!)
;; - use ispell.el
;; - display best possible score on a given deck at the end of the game
;; - use gamegrid.el for dealing with high score
;; - use defcustom for variables
;; - add unit testing
;; - use global state less (functional style programming)
;; - clock ticks with timer
;; - use face to display picked letter
;; (insert (propertize "foo" 'face 'highlight))
;; - display letter that are not in deck in word by word
;; - kill score buffer when quiting
;; - use a list instead of a string for the deck letters
;; - add command to shuffle the deck
;; - search TODO and MAYBE within the file
;; - document all functions
;; - navigate source code in other window to pretend working while playing
;; - put software in ELPA
;; - use ESC instead of Q to quit
;; - display congratulation for long words
;;; THANKS:
;; Inspiration from a game written by SpiceLabs http://spicelabs.in
;; I dedicate this to my grandmother who taught me to play Scrabble
;;; BUGS:
;;; INSTALLATION:
;; install aspell
;; M-x eval-buffer
;; M-x wpuzzle
;;; Code:
(require 'thingatpt)
(eval-when-compile
(require 'cl))
(defvar wpuzzle-time-limit 100
"Number of seconds the game will last.")
;; TODO reduce variables for high score
(defvar wpuzzle-high-score-buffer "wpuzzle-score"
"File for holding high scores.")
(defvar wpuzzle-high-score-directory
(locate-user-emacs-file "games/")
"A directory for storing game high score.")
(defvar wpuzzle-high-score-file
(concat wpuzzle-high-score-directory wpuzzle-high-score-buffer)
"Full path to file used for storing game high score.")
(defvar wpuzzle-buffer "*wpuzzle*"
"Game buffer")
(defvar wpuzzle-spell-buffer "*wpuzzle-spell*"
"Game spell buffer")
(defvar wpuzzle-length-score
'((0 . 0) (1 . 0) (2 . 0) (3 . 0) (4 . 0) (5 . 10)
(6 . 20) (7 . 30) (8 . 60) (9 . 85) (t 100))
"Score on length of word")
(defvar wpuzzle-frequency
'((?e . 150)
(?a . 84)
(?r . 75)
(?i . 75)
(?o . 71)
(?t . 69)
(?n . 66)
(?s . 100)
(?l . 54)
(?c . 45)
(?u . 36)
(?d . 70) ; crank up for verb ending in ed
(?p . 31)
(?m . 30)
(?h . 30)
(?g . 70) ; same for ing
(?b . 20)
(?f . 18)
(?y . 17)
(?w . 12)
(?k . 11)
(?v . 10)
(?x . 10) ; remaining letters are cranked up to
(?z . 10) ; add a bit of spice to the game :)
(?j . 10)
(?q . 10))
"List of english letter in order of frequency.
The number corespond to the chance of the letter being picked")
(defconst wpuzzle-scrabble
'((?a . 1) (?b . 3) (?c . 3) (?d . 2) (?e . 1) (?f . 4) (?g . 2) (?h . 4)
(?i . 1) (?j . 8) (?k . 5) (?l . 1) (?m . 3) (?n . 1) (?o . 1) (?p . 3)
(?q . 10) (?r . 1) (?s . 1) (?t . 1) (?u . 1) (?v . 4) (?w . 4) (?x . 8)
(?y . 4) (?z . 10))
"Scrabble letter values.")
;;; Clean functions
(defun wpuzzle-is-deck-good (deck)
"Return t when deck is nice to play with.
A nice deck has at least 3 vowels and consonnants. It has less
than 3 identical letters."
(let ((vowel-count 0)
consonnant-count
(vowel '(?a ?e ?i ?o ?y))
(letter (mapcar (lambda (el) (cons el 0)) (remove-duplicates deck))))
;; count vowels and consonnants
(dolist (element deck)
(when (member element vowel)
(incf vowel-count)))
(setq consonnant-count (- (length deck) vowel-count))
;; count letter
(dolist (element deck)
(incf (cdr (assoc element letter))))
;; MAYBE allow customization of hard coded values
(and (> vowel-count 2)
(> consonnant-count 2)
(not (remove-if (lambda (el) (< (cdr el) 3)) letter)))))
(defun wpuzzle-sum-word (input)
"Return sum of WORD with Scrabble letter value and length."
(+ (reduce '+ (mapcar (lambda (el)
(cdr (assoc el wpuzzle-scrabble))) input))
(cdr (or (assoc (length input) wpuzzle-length-score)
(assoc t wpuzzle-length-score)))))
(defun wpuzzle-calculate-score (word-list)
"Go through each word and sum them up."
(if word-list
(reduce '+ (mapcar (lambda (el) (wpuzzle-sum-word el)) word-list)) 0))
(defun wpuzzle-format-usage ()
(format "Welcome to word puzzle!
You have %d seconds to type as many word made out of the
letters presented. Longer words are worth more points. The letters
are scored with Scrabble value.
At any time press Q (upper case q) to quit.
Press enter to continue: " wpuzzle-time-limit))
(defun wpuzzle-format-game-over (word-list high-score)
"End of game message."
(let ((maximum-word-length 5) ;; account for the word "score"
(maximum-number-length 1)
(score (wpuzzle-calculate-score word-list)) format)
;; calculate width of word and number to line up nicely
;; TODO fix the folowing fugliness
(dolist (word word-list)
(when (> (length word) maximum-word-length)
(setq maximum-word-length (length word)))
(when (> (length (int-to-string (wpuzzle-sum-word word))) maximum-number-length)
(setq maximum-number-length (length (int-to-string (wpuzzle-sum-word word))))))
(setq format (concat "%-" (int-to-string maximum-word-length) "s "
"%" (int-to-string maximum-number-length) "d\n"))
(concat
"Game over.\n\n"
(mapconcat (lambda (el)
(format format (coerce el 'string) (wpuzzle-sum-word el))) word-list "")
(make-string (+ 3 maximum-word-length) ?-) "\n"
(format format "score" score) "\n"
(when (> score high-score)
(format "Congratulation, you beat the high score by %d point!\n\n" (- score high-score)))
"Press enter to play one more time or type Q to quit.")))
;; MAYBE coerce deck when it's really needed
(defun wpuzzle-format-game (deck input time-spent bad-spelling word-list)
(let ((deck (coerce deck 'string))
(time-left
(if (< time-spent wpuzzle-time-limit)
(- wpuzzle-time-limit time-spent) 0)))
(concat
(format "%d seconds Score %d High score %d\n\n"
(ceiling time-left)
(wpuzzle-calculate-score word-list)
(wpuzzle-set-or-retrieve-high-score nil))
" " (wpuzzle-format-deck (substring deck 0 3)) "\n"
(wpuzzle-format-deck (substring deck 3 7)) "\n"
" " (wpuzzle-format-deck (substring deck 7 10)) "\n"
(when bad-spelling
(format"\nThe word %s does not exist.\n" (coerce bad-spelling 'string)))
"\nEnter word: "
(coerce input 'string))))
(defun wpuzzle-format-deck (letter)
(mapconcat (lambda (el) (string el)) (coerce (upcase letter) 'list) " "))
;;; Dirty functions
;; TODO get rid of dummy
(defun wpuzzle-pick-letter (dummy)
"Pick a random letter."
(let* ((start 0)
(sum (let ((ret 0))
(dolist (el wpuzzle-frequency ret)
(setq ret (+ ret (cdr el))))))
(pick (random sum))
(ret ?e))
(dolist (el wpuzzle-frequency ret)
(when (< start pick)
(setq ret (car el)))
(setq start (+ start (cdr el)))) ret))
(defun wpuzzle-generate-deck ()
"Generate new deck."
(let ((deck (make-list 10 ?a)))
(while (not (wpuzzle-is-deck-good deck))
(setq deck (mapcar 'wpuzzle-pick-letter deck))) deck))
(defun wpuzzle-user-quit ()
(catch 'quit
(while t
(while (not (input-pending-p))
(sit-for 1))
(dolist (letter (coerce (read-key-sequence nil) 'list))
(cond ((= letter ?Q) (throw 'quit t))
((= letter 13) (throw 'quit nil)))))))
(defun wpuzzle-word-exist (buffer process word)
(when word
"Return t when WORD exists in dictionary."
(with-current-buffer buffer
(erase-buffer)
(process-send-string nil
(concat"%n\n^" word "\n"))
(while (accept-process-output process 0.1))
(goto-char (point-min))
(re-search-forward "^\*$" nil t))))
;; MAYBE turn off the awkwardness with a setf style macro
(defun wpuzzle-set-or-retrieve-high-score (set)
(when (not (file-exists-p wpuzzle-high-score-directory))
(make-directory wpuzzle-high-score-directory))
(save-window-excursion
(let ((buffer (find-file wpuzzle-high-score-file)) high-score)
(if set
(progn
(erase-buffer)
(insert (number-to-string set))
(save-buffer))
(goto-char (point-min))
(if (word-at-point)
(setq high-score (string-to-number (word-at-point))) 0)
(kill-buffer buffer)
high-score))))
(defun wpuzzle-change-letter (deck letter)
(catch 'found
(let ((new-deck))
(while t
(setq new-deck (substitute (wpuzzle-pick-letter nil) letter deck :count 1))
(when (wpuzzle-is-deck-good new-deck)
(throw 'found new-deck))))))
(defun wpuzzle ()
"Start game."
(interactive)
(let (player-input
time-spent
word-list
(high-score (wpuzzle-set-or-retrieve-high-score nil))
(spell-buffer (get-buffer-create wpuzzle-spell-buffer))
spell-process
(deck (wpuzzle-generate-deck))
bad-spelling
start-time)
(save-window-excursion
(with-current-buffer spell-buffer
(setq spell-process (start-process
"wpuzzle" (current-buffer)
"aspell" "-a" "-B" "--encoding=utf-8")))
(catch 'quit
(switch-to-buffer wpuzzle-buffer)
(erase-buffer)
(insert (wpuzzle-format-usage))
(when (wpuzzle-user-quit) (throw 'quit nil))
(setq start-time (float-time))
(while t
(setq time-spent (- (float-time) start-time))
(erase-buffer)
(insert (wpuzzle-format-game-over word-list high-score))
(when (> time-spent wpuzzle-time-limit)
(let ((score (wpuzzle-calculate-score word-list)))
(when (> score (wpuzzle-set-or-retrieve-high-score nil))
(wpuzzle-set-or-retrieve-high-score score)
(setq high-score score)))
(when (wpuzzle-user-quit) (throw 'quit nil))
(setq start-time (float-time)
word-list nil
bad-spelling nil
time-spent 0
player-input nil
deck (wpuzzle-generate-deck)
start-time (float-time)))
(erase-buffer)
(insert (wpuzzle-format-game deck player-input time-spent bad-spelling word-list))
(while (not (input-pending-p))
(sit-for 1))
(dolist (letter (coerce (read-key-sequence nil) 'list))
(cond ((= letter ?Q) (throw 'quit nil))
((= letter 13) ;; return key
(if (wpuzzle-word-exist spell-buffer spell-process player-input)
(setq word-list (append word-list (list player-input))
bad-spelling nil
player-input nil)
(setq bad-spelling player-input)
(setq player-input "")))
((and (>= letter ?a)
(<= letter ?z)
(member letter deck))
(setq deck (wpuzzle-change-letter deck letter))
(setq player-input (append player-input (list letter))))))))
(kill-buffer wpuzzle-buffer)
(kill-buffer spell-buffer))))
;; stuff to debug
(when nil
(progn
(setq wpuzzle-time-limit 100)
(global-set-key '[f5]
(lambda ()
(interactive)
(save-buffer)
(eval-buffer)
(wpuzzle)))
(global-set-key '[f6]
(lambda ()
(interactive)
(edebug-defun)
(save-buffer)
(wpuzzle)))))
(provide 'wpuzzle)
;; Copyright (C) 2012 Ivan Kanis
;; Author: Ivan Kanis
;;
;; This program is free software ; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation ; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY ; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program ; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;;
;; vi:et:sw=4:ts=4:
;; Local Variables:
;; compile-command: "make"
;; End:
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 9:15 how to turn off cl warning Ivan Kanis
@ 2012-12-15 9:22 ` Bastien
2012-12-15 10:55 ` Ivan Kanis
2012-12-15 9:34 ` Thierry Volpiatto
2012-12-15 11:51 ` Grégoire Jadi
2 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2012-12-15 9:22 UTC (permalink / raw)
To: Ivan Kanis; +Cc: emacs devel
Hi Ivan,
Ivan Kanis <ivan.kanis@googlemail.com> writes:
> When I compile my program I get the following warnings:
>
> In wpuzzle-format-game-over:
> wpuzzle.el:185:46:Warning: function `coerce' from cl package called at runtime
>
> I want to use coerce, how do I turn off the warning. I have attached the
> file I am compiling.
You canremove cl-functions from `byte-compile-warning-types'.
HTH,
--
Bastien
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 9:15 how to turn off cl warning Ivan Kanis
2012-12-15 9:22 ` Bastien
@ 2012-12-15 9:34 ` Thierry Volpiatto
2012-12-15 19:01 ` Ivan Kanis
2012-12-15 11:51 ` Grégoire Jadi
2 siblings, 1 reply; 10+ messages in thread
From: Thierry Volpiatto @ 2012-12-15 9:34 UTC (permalink / raw)
To: emacs-devel
Ivan Kanis <ivan.kanis@googlemail.com> writes:
> Hi,
>
> When I compile my program I get the following warnings:
>
> In wpuzzle-format-game-over:
> wpuzzle.el:185:46:Warning: function `coerce' from cl package called at runtime
>
> I want to use coerce, how do I turn off the warning.
Add to eof:
;; Local variables:
;; byte-compile-warnings: (not cl-functions)
;; End:
> I have attached the file I am compiling.
--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 9:22 ` Bastien
@ 2012-12-15 10:55 ` Ivan Kanis
2012-12-15 11:34 ` Andreas Schwab
0 siblings, 1 reply; 10+ messages in thread
From: Ivan Kanis @ 2012-12-15 10:55 UTC (permalink / raw)
To: Bastien; +Cc: emacs devel
Bastien <bzg@gnu.org> wrote:
> You canremove cl-functions from `byte-compile-warning-types'.
I tried:
(eval-when-compile
(require 'cl)
(setq byte-compile-warning-type
(remove 'cl-functions byte-compile-warning-types)))
But got one more warning for my effort:
In toplevel form:
wpuzzle.el:50:9:Warning: assignment to free variable
`byte-compile-warning-type'
In wpuzzle-is-deck-good:
wpuzzle.el:105:70:Warning: function `remove-duplicates' from cl package called
at runtime
--
Ivan Kanis
http://ivan.kanis.fr
A faith is something you die for; a doctrine is something you kill
for: there is all the difference in the world.
-- Tony Benn
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 10:55 ` Ivan Kanis
@ 2012-12-15 11:34 ` Andreas Schwab
0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2012-12-15 11:34 UTC (permalink / raw)
To: Ivan Kanis; +Cc: Bastien, emacs devel
Ivan Kanis <ivan.kanis@googlemail.com> writes:
> (eval-when-compile
> (require 'cl)
> (setq byte-compile-warning-type
^^^^
> (remove 'cl-functions byte-compile-warning-types)))
^^^^^
Look closer.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 9:15 how to turn off cl warning Ivan Kanis
2012-12-15 9:22 ` Bastien
2012-12-15 9:34 ` Thierry Volpiatto
@ 2012-12-15 11:51 ` Grégoire Jadi
2 siblings, 0 replies; 10+ messages in thread
From: Grégoire Jadi @ 2012-12-15 11:51 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 417 bytes --]
Ivan Kanis <ivan.kanis@googlemail.com> writes:
> Hi,
>
> When I compile my program I get the following warnings:
>
> In wpuzzle-format-game-over:
> wpuzzle.el:185:46:Warning: function `coerce' from cl package called at runtime
>
> I want to use coerce, how do I turn off the warning. I have attached the
> file I am compiling.
You can disable those warnings like this:
(byte-compile-disable-warning 'cl-functions)
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
@ 2012-12-15 12:42 Ivan Kanis
0 siblings, 0 replies; 10+ messages in thread
From: Ivan Kanis @ 2012-12-15 12:42 UTC (permalink / raw)
To: emacs devel; +Cc: Andreas Schwab
Andreas Schwab <schwab@linux-m68k.org> wrote:
> Look closer.
Gaaah...
I put an s at the end of type and I still get the warnings.
(eval-when-compile
(require 'cl)
(setq byte-compile-warning-types
(remove 'cl-functions byte-compile-warning-types)))
Are the warnings still meaningful? As far as I can see the cl functions
are autoloaded.
--
Ivan Kanis
http://ivan.kanis.fr
In big industry new ideas are invited to rear their heads so they can
be clobbered at once. The idea department of a big firm is a sort of
lab for isolating dangerous viruses.
-- Marshall McLuhan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 9:34 ` Thierry Volpiatto
@ 2012-12-15 19:01 ` Ivan Kanis
2012-12-15 19:09 ` Thierry Volpiatto
0 siblings, 1 reply; 10+ messages in thread
From: Ivan Kanis @ 2012-12-15 19:01 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: emacs-devel
Thierry Volpiatto <thierry.volpiatto@gmail.com> a écrit
> Ivan Kanis <ivan.kanis@googlemail.com> writes:
>
>> I want to use coerce, how do I turn off the warning.
> Add to eof:
>
> ;; Local variables:
> ;; byte-compile-warnings: (not cl-functions)
> ;; End:
Nice, thank you!
I have one left:
In end of data:
wpuzzle.el:371:1:Warning: the following functions might not be defined at
runtime: remove-duplicates, remove-if, reduce, coerce, substitute
--
Ivan Kanis
http://ivan.kanis.fr
Réfléchir. - Attendre quelques jours avant de ne pas changer d'avis.
-- Auguste Detœuf
J'écoute « Hubert-Felix Thiefaine - Alligators 427 ».
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 19:01 ` Ivan Kanis
@ 2012-12-15 19:09 ` Thierry Volpiatto
2012-12-15 20:45 ` Ivan Kanis
0 siblings, 1 reply; 10+ messages in thread
From: Thierry Volpiatto @ 2012-12-15 19:09 UTC (permalink / raw)
To: Ivan Kanis; +Cc: emacs-devel
Ivan Kanis <ivan.kanis@googlemail.com> writes:
> Thierry Volpiatto <thierry.volpiatto@gmail.com> a écrit
>
>> Ivan Kanis <ivan.kanis@googlemail.com> writes:
>>
>>> I want to use coerce, how do I turn off the warning.
>> Add to eof:
>>
>> ;; Local variables:
>> ;; byte-compile-warnings: (not cl-functions)
>> ;; End:
>
> Nice, thank you!
>
> I have one left:
>
> In end of data:
> wpuzzle.el:371:1:Warning: the following functions might not be defined at
> runtime: remove-duplicates, remove-if, reduce, coerce, substitute
Probably you have (eval-when-compile (require 'cl)),
using only (require 'cl) should work.
--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: how to turn off cl warning
2012-12-15 19:09 ` Thierry Volpiatto
@ 2012-12-15 20:45 ` Ivan Kanis
0 siblings, 0 replies; 10+ messages in thread
From: Ivan Kanis @ 2012-12-15 20:45 UTC (permalink / raw)
To: Thierry Volpiatto; +Cc: emacs-devel
Thierry Volpiatto <thierry.volpiatto@gmail.com> a écrit
> Probably you have (eval-when-compile (require 'cl)),
> using only (require 'cl) should work.
Thanks that did it.
I thought it was a no no to require cl but I can't remember why...
--
Ivan Kanis
http://ivan.kanis.fr
Le naturel est bien plus sûr:
Le mot doit mûrir sur l'idée,
Et puis tomber comme un fruit mûr.
-- Charles Nodier
J'écoute « Hubert-Felix Thiefaine - Alligators 427 ».
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-12-15 20:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-15 9:15 how to turn off cl warning Ivan Kanis
2012-12-15 9:22 ` Bastien
2012-12-15 10:55 ` Ivan Kanis
2012-12-15 11:34 ` Andreas Schwab
2012-12-15 9:34 ` Thierry Volpiatto
2012-12-15 19:01 ` Ivan Kanis
2012-12-15 19:09 ` Thierry Volpiatto
2012-12-15 20:45 ` Ivan Kanis
2012-12-15 11:51 ` Grégoire Jadi
-- strict thread matches above, loose matches on Subject: below --
2012-12-15 12:42 Ivan Kanis
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.