From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Kanis Newsgroups: gmane.emacs.devel Subject: how to turn off cl warning Date: Sat, 15 Dec 2012 10:15:13 +0100 Message-ID: <8738z7znfi.fsf@googlemail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1355562931 21100 80.91.229.3 (15 Dec 2012 09:15:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 15 Dec 2012 09:15:31 +0000 (UTC) To: emacs devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 15 10:15:46 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TjnqT-0002rH-RR for ged-emacs-devel@m.gmane.org; Sat, 15 Dec 2012 10:15:46 +0100 Original-Received: from localhost ([::1]:37154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjnqG-0007ih-Ot for ged-emacs-devel@m.gmane.org; Sat, 15 Dec 2012 04:15:32 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjnqC-0007br-8K for emacs-devel@gnu.org; Sat, 15 Dec 2012 04:15:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tjnq8-0002u4-14 for emacs-devel@gnu.org; Sat, 15 Dec 2012 04:15:28 -0500 Original-Received: from mail-wi0-f169.google.com ([209.85.212.169]:42009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tjnq7-0002tf-Nd for emacs-devel@gnu.org; Sat, 15 Dec 2012 04:15:23 -0500 Original-Received: by mail-wi0-f169.google.com with SMTP id hq12so1046318wib.0 for ; Sat, 15 Dec 2012 01:15:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:face:date:message-id:user-agent :mime-version:content-type; bh=Ggk0RU9kLMmgCEY1p2E3MNWXm5kltwZSibhw3Ca3l7k=; b=zRvRXB6YiX2r+Z0r6Iqe0dyQgl+m9IPg31Qa+KRH7wUjrrCwf9KOdyZ9guVXYwBJ/1 t+kcEFiXMuh7o7I3h/HkdY4QqDAA6U3+G+OWxQTzwYRPMDQlpXcpUa9e2gSGIn+M2/Fz 79ozmJwM3YJ3NWcnzrAdxrSUKd3/DiTnKLp1EHw7iykDB1IH2q6XPLXnnRlU9y/+pBF1 BT3S76Rvs5SYgb1e0jHqhbFojmAFWxrkWrcL3yZiikdNE338jAWtSDcJg1bKgsBJ+/Yo azOTIAiQ+UV+w57eS/VccK3U9iMKQnHDQIq+1SR0ywcC8KgEf6+XB4xCCEyqW1qsD1LM 547g== X-Received: by 10.180.24.9 with SMTP id q9mr6653757wif.14.1355562922514; Sat, 15 Dec 2012 01:15:22 -0800 (PST) Original-Received: from tao (lns-c10k-ft-02-t2-89-83-137-164.dsl.sta.abo.bbox.fr. [89.83.137.164]) by mx.google.com with ESMTPS id h19sm1148180wiv.7.2012.12.15.01.15.19 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 15 Dec 2012 01:15:21 -0800 (PST) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAAB5QTFRF IBkXUxMTOCwoTC4qcUY8iFxQmmper31txpaJ/v/8aKZ1oAAAAcVJREFUOMt100tu2zAQAFDCXnUZ oAcIqG68LZULVLQBbwuSiffm6AIRRyeotAySJoVu2+FPpJWWC3/4NKOZocSW/yxWfnJ2+Bdwzhj7 8gleWVy7DXC2rkMNr2V/zRbghXIwthf3VbIA9Ffc71vZCSFyCEsBggtNS8ludwvfmhYA0Vn9o4DP zMWxR7+cPWzAYFzwM0ModtdmcDbDS6i/hT7L+RZof5yCXGrYe5jn2YO6BYMjgY+51tCIAqHgBLwR pwLnGuRjAKyBJkuN4yd4U92uCY1vUr2D/c5b8DuxyQwfOHUeaLqDJhnkkuGXbB56h2C1IVBdgncc bBi6feroa9B6jUDojnQPQKupbyXyeeCE1oT7Oqrt+SnfY3mkiyGA/3AmD3H5g32CcBx6hY8pRkwJ 9PpcjRGobUfprFnhAa1vepwcgMOhwG+pdSgKHFU9HAvoAH6XUl7lDUCCq5Qb6GMbVm3Aj++qDYCt wdBc/YHgOFCmS3mjDMRcSE2qY4E3Q3PVIQRQmeodNH4QEbRUFZzW+VotzwX4yTcRTySOML1qjcE5 hTirVqDHkMAP0PjAywp3d18JZtqzvr9zDYD+GaSKtE6Zlr/DLPNFmOcvBAAAAABJRU5ErkJggg== User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.212.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:155570 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: application/emacs-lisp; charset=utf-8 Content-Disposition: attachment; filename=wpuzzle.el Content-Transfer-Encoding: quoted-printable ;; -*- 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-num= ber-length) (setq maximum-number-length (length (int-to-string (wpuzzle-sum-wor= d 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 'strin= g))) "\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 ((=3D letter ?Q) (throw 'quit t)) ((=3D 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 :c= ount 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=3Dutf-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-spe= lling word-list)) (while (not (input-pending-p)) (sit-for 1)) (dolist (letter (coerce (read-key-sequence nil) 'list)) (cond ((=3D letter ?Q) (throw 'quit nil)) ((=3D letter 13) ;; return key (if (wpuzzle-word-exist spell-buffer spell-process playe= r-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 (>=3D letter ?a) (<=3D 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=3D4:ts=3D4: ;; Local Variables: ;; compile-command: "make" ;; End: --=-=-=--