all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Erich Neuwirth <erich.neuwirth@univie.ac.at>
To: Dwaddle <rmborchers@gmail.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Strange results
Date: Sat, 7 Sep 2013 09:22:04 +0200	[thread overview]
Message-ID: <E424C007-0019-466E-B825-C8E9CA491D13@univie.ac.at> (raw)
In-Reply-To: <a394ec7e-20bc-4e5f-a2fa-a0ea376c096d@googlegroups.com>

You need to learn about set and setq vs let

Von meinem iPad gesendet

Am 07.09.2013 um 09:06 schrieb Dwaddle <rmborchers@gmail.com>:

> Hi
> 
> i've been dabbling around in elisp for a while. Made this function
> 
> The issue is the byte var which 'remembers' the result from a previous calculation.
> 
> (integer-bin 5)     [0 0 0 0 0 1 0 1]
> (integer-bin 3)     [0 0 0 0 0 1 1 1]
> 
> To beat the critics I know it isn't very clean programmed and a loop would make it al lot shorter
> 
> <code>
> (defun integer-bin (dec)
>  "Convert integer to binairy"
>  (setq 8bit [128 64 32 16 8 4 2 1])
>  (setq byte [0 0 0 0 0 0 0 0])
>  (if (= 1 (/ dec (aref 8bit 0))) (when
>                                      (aset byte 0 1)
>                                      (setq dec (- dec 128))))
>  (if (< 0 dec)
>  (if (= 1 (/ dec (aref 8bit 1))) (when
>                                      (aset byte 1 1)
>                                      (setq dec (- dec 64)))))
>  (if (< 0 dec)
>  (if (= 1 (/ dec (aref 8bit 2))) (when
>                                      (aset byte 2 1)
>                                      (setq dec (- dec 32)))))
>  (if (< 0 dec)
>  (if (= 1 (/ dec (aref 8bit 3))) (when
>                                      (aset byte 3 1)
>                                      (setq dec (- dec 16)))))
>  (if (< 0 dec)
>  (if (= 1 (/ dec (aref 8bit 4))) (when
>                                      (aset byte 4 1)
>                                      (setq dec (- dec 8)))))
>  (if (< 0 dec)
>  (if (= 1 (/ d<ec (aref 8bit 5))) (when
>                                      (aset byte 5 1)
>                                      (setq dec (- dec 4)))))
>  (if (< 0 dec)
>  (if (= 1 (/ dec (aref 8bit 6))) (when
>                                      (aset byte 6 1)
>                                      (setq dec (- dec 2)))))
> (if (< 0 dec)
>  (if (= 1 1) (when (aset byte 7 1)
>                    (setq dec (- dec 1)))))
> (print byte)
> )
> </code> 



  reply	other threads:[~2013-09-07  7:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-07  7:06 Strange results Dwaddle
2013-09-07  7:22 ` Erich Neuwirth [this message]
2013-09-07  7:49 ` Dwaddle
2013-09-07  7:59   ` Neuwirth Erich
2013-09-07  8:20 ` Dwaddle
2013-09-07 12:34   ` Pascal J. Bourguignon
2013-09-07 13:54     ` Neuwirth Erich
2013-11-03  0:53 ` WJ

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E424C007-0019-466E-B825-C8E9CA491D13@univie.ac.at \
    --to=erich.neuwirth@univie.ac.at \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rmborchers@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.