this post was submitted on 17 Oct 2023
1 points (100.0% liked)

Lisp

61 readers
3 users here now

founded 2 years ago
MODERATORS
 

For example, I've seen someone defining a package like so:

(defpackage :foobar
  (:use :cl))

instead of:

(defpackage foobar
  (:use cl))

Is there any actual difference? Or it's just a personal preference, and has no effect on the program at all?

you are viewing a single comment's thread
view the rest of the comments
[–] lispm@alien.top 1 points 2 years ago (9 children)

The symbol will be interned in some package. A keyword symbol is in the package KEYWORD. That's slightly better than to use the symbol of some other package, which "pollutes" that package with that symbol. ;-)

An alternative, out of fashion because of the upper case, is to use a string "FOOBAR".

[–] fvf@alien.top 1 points 2 years ago (5 children)

Better use #:foobar to make it a symbol that isn't interned at all.

[–] IReadToKnowIAmAlone@alien.top 1 points 2 years ago (4 children)

Is interning that bad ?

Perhaps I'm misunderstanding it, but IMHO, interning means that particular symbol string will be recorded/hashed once in a map like data structure and thereafter will be referenced everywhere using a pointer to it, whereas frequently used but uninterned symbol would imply a new string always. i.e. memory savings with interning, but ofcourse too many interned symbols which are not used at all would be waste.

Any clarifications to my (mis)understanding are welcome.

Thanks!

[–] fvf@alien.top 1 points 2 years ago

An interned symbol will hang around forever, adding load to GC, memory footprint, symbol clutter, etc. A non-interned symbol has nearly zero of any of these costs.

These are very minor considerations, perhaps only meaningful for release-quality library code.

load more comments (3 replies)
load more comments (3 replies)
load more comments (6 replies)