all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Symbol's value as variable is void: defun
@ 2018-02-02  2:54 Davin Pearson
  2018-02-02  3:27 ` Emanuel Berg
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Davin Pearson @ 2018-02-02  2:54 UTC (permalink / raw)
  To: help-gnu-emacs

;; With the following defun in effect:

(defun load-file-most-recent (file)
  ;;(setq file (concat (car load-path) "/" file))
  (assert (string-match "\\.el$" file))
  (setq other (substring file 0 (match-beginning 0)))
  (setq other (concat other ".elc"))
  (cond
   ((and (file-exists-p file) (file-exists-p other))
    (setq date-modified-file (nth 5 (file-attributes file)))
    (setq date-modified-other (nth 5 (file-attributes other)))
    (setq file-older-than-other-p
          (if (>= (nth 0 date-modified-file) (nth 0 date-modified-other))
              (if (>= (nth 1 date-modified-file) (nth 1 date-modified-other))
                  (if (>= (nth 2 date-modified-file) (nth 2 date-modified-other))
                      t
                    nil)
                nil)
            nil))
    (if file-older-than-other-p
        (progn
          (message "loading file %s" file)
          (load-file file))
      (message "loading file %s" other)
      (load-file other))
    )
   ((file-exists-p file)
    (load-file file)
    )
   ((file-exists-p other)
    (load-file other)
    )
   (t
    (assert (not (file-exists-p file)))
    (assert (not (file-exists-p other)))
    (error "Should never happen, file=%s, other=%s" file other))
   )
  )

(load-file-most-recent "~/lisp++-projects/c++2lisp++-stage-1-purge-comments.el")

;; gives the following diagnostic: Symbol's value as variable is void:
;; defun. 

Here is the contents of the offending file:

http://davinpearson.com/binaries/c++2lisp++-stage-1-purge-comments.elc



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-02  2:54 Symbol's value as variable is void: defun Davin Pearson
@ 2018-02-02  3:27 ` Emanuel Berg
  2018-02-02  7:50   ` tomas
  2018-02-02  8:22   ` Emanuel Berg
  2018-02-02  7:48 ` tomas
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 10+ messages in thread
From: Emanuel Berg @ 2018-02-02  3:27 UTC (permalink / raw)
  To: help-gnu-emacs

Davin Pearson wrote:

> (defun load-file-most-recent (file) ...

Man, you have some serious style issues!

- lots of `setq's, and sequential `setq' to the
  same variable! here, rely on `let' and `let*'
  instead, and do it one thing at a time, then
  stay out
  
- long function

- everything tangled up: `setq' within `cond',
  deeply nested `if's within `setq', ...

You don't need explicit nils for single-branch
`if's:

    (if t   1)  ; 1
    (if nil 1)  ; nil

But for `if's with only one branch you are
benefitted from instead using `when' (and
`unless' for "if not") as this will drop the
need for explicit `progn's for the
multiform branch.

(when   t   1)   ; 1
(unless t   1)   ; nil

(when   nil 1)   ; nil
(unless nil 1)   ; 1

(when   nil 1 2) ; nil
(unless nil 1 2) ; 2 is return but "1" also happens

(when   t   1 2) ; ditto
(unless t   1 2) ; nil

-- 
underground experts united
http://user.it.uu.se/~embe8573


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-02  2:54 Symbol's value as variable is void: defun Davin Pearson
  2018-02-02  3:27 ` Emanuel Berg
@ 2018-02-02  7:48 ` tomas
  2018-02-02 11:39 ` Ben Bacarisse
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: tomas @ 2018-02-02  7:48 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Feb 01, 2018 at 06:54:16PM -0800, Davin Pearson wrote:
> ;; With the following defun in effect:
> 
> (defun load-file-most-recent (file)
>   ;;(setq file (concat (car load-path) "/" file))
>   (assert (string-match "\\.el$" file))
>   (setq other (substring file 0 (match-beginning 0)))
>   (setq other (concat other ".elc"))
>   (cond
>    ((and (file-exists-p file) (file-exists-p other))
>     (setq date-modified-file (nth 5 (file-attributes file)))
>     (setq date-modified-other (nth 5 (file-attributes other)))
>     (setq file-older-than-other-p
>           (if (>= (nth 0 date-modified-file) (nth 0 date-modified-other))
>               (if (>= (nth 1 date-modified-file) (nth 1 date-modified-other))
>                   (if (>= (nth 2 date-modified-file) (nth 2 date-modified-other))
>                       t
>                     nil)
>                 nil)
>             nil))
>     (if file-older-than-other-p
>         (progn
>           (message "loading file %s" file)
>           (load-file file))
>       (message "loading file %s" other)
>       (load-file other))
>     )
>    ((file-exists-p file)
>     (load-file file)
>     )
>    ((file-exists-p other)
>     (load-file other)
>     )
>    (t
>     (assert (not (file-exists-p file)))
>     (assert (not (file-exists-p other)))
>     (error "Should never happen, file=%s, other=%s" file other))
>    )
>   )
> 
> (load-file-most-recent "~/lisp++-projects/c++2lisp++-stage-1-purge-comments.el")
> 
> ;; gives the following diagnostic: Symbol's value as variable is void:
> ;; defun. 

I don't quite understand: the problem seems to be in the file
loaded, i.e. in "c++2lisp++-stage-1-purge-comments.el", right?
Can we see that?

> Here is the contents of the offending file:
> 
> http://davinpearson.com/binaries/c++2lisp++-stage-1-purge-comments.elc

Hm. I can't read .elc too well :-) do you have an uncompiled
version?

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlp0F8QACgkQBcgs9XrR2kbSBQCfUeZJmM/fPGWBVyIADq7h297Z
cKIAn2q60X1Q+HaRIoZaqrovTPmCf5Ul
=LMp9
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-02  3:27 ` Emanuel Berg
@ 2018-02-02  7:50   ` tomas
  2018-02-02  8:22   ` Emanuel Berg
  1 sibling, 0 replies; 10+ messages in thread
From: tomas @ 2018-02-02  7:50 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Feb 02, 2018 at 04:27:23AM +0100, Emanuel Berg wrote:
> Davin Pearson wrote:
> 
> > (defun load-file-most-recent (file) ...
> 
> Man, you have some serious style issues!

Emanuel: while I do agree in some of the points you make
(mind you, not in all, tastes are like that!), you could
be well a tad more polite when criticizing style.

Holy smoke.

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlp0GCkACgkQBcgs9XrR2kYttQCdFEz/Ik3SU2H/mcOkl9E/27V/
fWIAnjF4jG43+SfIWJ14zPI9X2G4nP2h
=LIyg
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-02  3:27 ` Emanuel Berg
  2018-02-02  7:50   ` tomas
@ 2018-02-02  8:22   ` Emanuel Berg
  1 sibling, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2018-02-02  8:22 UTC (permalink / raw)
  To: help-gnu-emacs

tomas wrote:

>>> (defun load-file-most-recent (file) ...
>> 
>> Man, you have some serious style issues!
>
> Emanuel: while I do agree in some of the
> points you make (mind you, not in all, tastes
> are like that!), you could be well a tad more
> polite when criticizing style.

? What do you mean "more polite"?

As for the style, it is most likely what is
causing the problem in the first place, and if
it isn't, it is what is making the problem
difficult to debug.

-- 
underground experts united
http://user.it.uu.se/~embe8573


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-02  2:54 Symbol's value as variable is void: defun Davin Pearson
  2018-02-02  3:27 ` Emanuel Berg
  2018-02-02  7:48 ` tomas
@ 2018-02-02 11:39 ` Ben Bacarisse
  2018-02-02 18:10 ` John Mastro
  2018-02-05  2:59 ` Davin Pearson
  4 siblings, 0 replies; 10+ messages in thread
From: Ben Bacarisse @ 2018-02-02 11:39 UTC (permalink / raw)
  To: help-gnu-emacs

Davin Pearson <davin.pearson@gmail.com> writes:

> ;; With the following defun in effect:
>
> (defun load-file-most-recent (file)
>   ;;(setq file (concat (car load-path) "/" file))
>   (assert (string-match "\\.el$" file))
>   (setq other (substring file 0 (match-beginning 0)))
>   (setq other (concat other ".elc"))
>   (cond
>    ((and (file-exists-p file) (file-exists-p other))
>     (setq date-modified-file (nth 5 (file-attributes file)))
>     (setq date-modified-other (nth 5 (file-attributes other)))
>     (setq file-older-than-other-p
>           (if (>= (nth 0 date-modified-file) (nth 0 date-modified-other))
>               (if (>= (nth 1 date-modified-file) (nth 1 date-modified-other))
>                   (if (>= (nth 2 date-modified-file) (nth 2 date-modified-other))
>                       t
>                     nil)
>                 nil)
>             nil))
>     (if file-older-than-other-p
>         (progn
>           (message "loading file %s" file)
>           (load-file file))
>       (message "loading file %s" other)
>       (load-file other))
>     )
>    ((file-exists-p file)
>     (load-file file)
>     )
>    ((file-exists-p other)
>     (load-file other)
>     )
>    (t
>     (assert (not (file-exists-p file)))
>     (assert (not (file-exists-p other)))
>     (error "Should never happen, file=%s, other=%s" file other))
>    )
>   )
>
> (load-file-most-recent "~/lisp++-projects/c++2lisp++-stage-1-purge-comments.el")
>
> ;; gives the following diagnostic: Symbol's value as variable is void:
> ;; defun. 
>
> Here is the contents of the offending file:
>
> http://davinpearson.com/binaries/c++2lisp++-stage-1-purge-comments.elc

The problem is reported to be in that file and is (as far as I can tell)
unrelated to the code you show above.  You'd have to post the source for
that compiler file to more help.

-- 
Ben.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-02  2:54 Symbol's value as variable is void: defun Davin Pearson
                   ` (2 preceding siblings ...)
  2018-02-02 11:39 ` Ben Bacarisse
@ 2018-02-02 18:10 ` John Mastro
  2018-02-05  2:59 ` Davin Pearson
  4 siblings, 0 replies; 10+ messages in thread
From: John Mastro @ 2018-02-02 18:10 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Davin Pearson

Davin Pearson <davin.pearson@gmail.com> wrote:
> ;; With the following defun in effect:
>
> (defun load-file-most-recent (file)

[snip]

> (load-file-most-recent "~/lisp++-projects/c++2lisp++-stage-1-purge-comments.el")
>
> ;; gives the following diagnostic: Symbol's value as variable is void:
> ;; defun.

Would using `load' with `load-prefer-newer' set to non-nil work for you
(and save you from needing to implement `load-file-most-recent'
yourself)?

[ I'm basing this mostly on the name - I only glanced at the definition
  of `load-file-most-recent'.]

        John



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-02  2:54 Symbol's value as variable is void: defun Davin Pearson
                   ` (3 preceding siblings ...)
  2018-02-02 18:10 ` John Mastro
@ 2018-02-05  2:59 ` Davin Pearson
  2018-02-05  3:04   ` Emanuel Berg
  4 siblings, 1 reply; 10+ messages in thread
From: Davin Pearson @ 2018-02-05  2:59 UTC (permalink / raw)
  To: help-gnu-emacs

In response to your postings I have placed the *.el source code files on my Website for all to view.

Here are the location of some troublesome files.

When I try to execute load-2 on the following files,

(defun load-2 (file)
   (load-file file))

http://davinpearson.com/binaries/c++2lisp++-stage-1-purge-comments.elc
http://davinpearson.com/binaries/c++2lisp++-stage-2-beautify.elc
http://davinpearson.com/binaries/c++2lisp++-stage-3-minise.elc
http://davinpearson.com/binaries/c++2lisp++-stage-4-maxise.elc
http://davinpearson.com/binaries/c++2lisp++-stage-5-fill-methods.elc

When I try to load the file c++2lisp++-stage-1-purge-comments.elc it returns with value t

When I try to load the file c++2lisp++-stage-1-purge-comments.elc it it returns with value t

When I try to load the file c++2lisp++-stage-2-beautify.elc it says (invalid-function d-assert)

When I try to load the file c++2lisp++-stage-3-minise.elc it returns with value t

When I try to load the file c++2lisp++-stage-4-maxise.elc it returns with value t

When I try to load the file c++2lisp++-stage-5-fill-methods.elc it says (void-variable defun)

In each of the offending files I have placed the following code at the beginning of it:

(require 'cl)
(require 'early-bindings)

where early-bindings.el can be found at my Website at the following
location:

http://davinpearson.com/binaries/early-bindings.el

I haved placed the source *.el and compiled versions *.elc of my code on my website
a the following locations:

http://davinpearson.com/binaries/c++2lisp++-stage-1-purge-comments.el
http://davinpearson.com/binaries/c++2lisp++-stage-2-beautify.el
http://davinpearson.com/binaries/c++2lisp++-stage-3-minise.el
http://davinpearson.com/binaries/c++2lisp++-stage-4-maxise.el
http://davinpearson.com/binaries/c++2lisp++-stage-5-fill-methods.el


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-05  2:59 ` Davin Pearson
@ 2018-02-05  3:04   ` Emanuel Berg
  2018-02-05  6:39     ` Davin Pearson
  0 siblings, 1 reply; 10+ messages in thread
From: Emanuel Berg @ 2018-02-05  3:04 UTC (permalink / raw)
  To: help-gnu-emacs

Davin Pearson wrote:

> In response to your postings I have placed the
> *.el source code files on my Website for all
> to view. [...]
>
> When I try to load the file
> c++2lisp++-stage-2-beautify.elc it says
> (invalid-function d-assert) [...]

Does it byte compile with no error messages
or even warnings?

-- 
underground experts united
http://user.it.uu.se/~embe8573


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Symbol's value as variable is void: defun
  2018-02-05  3:04   ` Emanuel Berg
@ 2018-02-05  6:39     ` Davin Pearson
  0 siblings, 0 replies; 10+ messages in thread
From: Davin Pearson @ 2018-02-05  6:39 UTC (permalink / raw)
  To: help-gnu-emacs

On Monday, February 5, 2018 at 4:04:54 PM UTC+13, Emanuel Berg wrote:
> Davin Pearson wrote:
> 
> > In response to your postings I have placed the
> > *.el source code files on my Website for all
> > to view. [...]
> >
> > When I try to load the file
> > c++2lisp++-stage-2-beautify.elc it says
> > (invalid-function d-assert) [...]
> 
> Does it byte compile with no error messages
> or even warnings?
> 
> -- 
> underground experts united
> http://user.it.uu.se/~embe8573


(setq load-path (cons "~/dlisp/" load-path))

(load-file "~/lisp++-projects/c++2lisp++.el")
(load-file "~/lisp++-projects/lisp++2c++.el")

(defun byte-compile-folder ()
  (interactive)
  (progn
    (delete-other-windows)
    (let ((ptr (directory-files "~/lisp++-projects/" nil "\\.el$")))
      (while ptr
        (when (file-newer-than-file-p (car ptr) (concat (car ptr) "c"))
          (message "Byte-compiling file %s" (car ptr))
          (byte-compile-file (car ptr) 'LOAD))
        (setq ptr (cdr ptr))
        )))
  )

The errors went away when I removed the compiler errors from the above defun.

Thank you for bringing it to my attention.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-02-05  6:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-02  2:54 Symbol's value as variable is void: defun Davin Pearson
2018-02-02  3:27 ` Emanuel Berg
2018-02-02  7:50   ` tomas
2018-02-02  8:22   ` Emanuel Berg
2018-02-02  7:48 ` tomas
2018-02-02 11:39 ` Ben Bacarisse
2018-02-02 18:10 ` John Mastro
2018-02-05  2:59 ` Davin Pearson
2018-02-05  3:04   ` Emanuel Berg
2018-02-05  6:39     ` Davin Pearson

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.