[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Omitting code at load or compile time

Jeremy Smith

7/27/2015 9:30:00 PM

Hi Folks,

I'm distributing a Lisp program, as a Clisp binary, and I want to have a
'demo' version.

This demo version would be lacking features compared to the paid version.

In C, if I want to remove some code for a demo version, I have:

#define DEMO

And later down,

#ifndef DEMO
printf("paid version");
#endif

How do I do this in Lisp? Say we have:

(format t "paid version")

How can I omit that at 'load' or 'compile' time?

Thanks for much for any help,

Jeremy.
6 Answers

Matthew Carter

7/27/2015 9:50:00 PM

0

Jeremy Smith <jeremy@decompiler.org> writes:

> Hi Folks,
>
> I'm distributing a Lisp program, as a Clisp binary, and I want to have a
> 'demo' version.
>
> This demo version would be lacking features compared to the paid version.
>
> In C, if I want to remove some code for a demo version, I have:
>
> #define DEMO
>
> And later down,
>
> #ifndef DEMO
> printf("paid version");
> #endif
>
> How do I do this in Lisp? Say we have:
>
> (format t "paid version")
>
> How can I omit that at 'load' or 'compile' time?
>
> Thanks for much for any help,
>
> Jeremy.

(push :PAID-VERSION *features*) ;; Only include if they paid

#+PAID-VERSION
(format t "paid version")

#-PAID-VERSION
(format t "not the paid version")

--
Matthew Carter (m@ahungry.com)
http://a...

Jeremy Smith

7/27/2015 10:24:00 PM

0

> (push :PAID-VERSION *features*) ;; Only include if they paid
>
> #+PAID-VERSION
> (format t "paid version")
>
> #-PAID-VERSION
> (format t "not the paid version")

This works great! Thanks so much!

Cheers,

Jeremy.

rpw3

7/28/2015 3:13:00 PM

0

Jeremy Smith <jeremy@decompiler.org> wrote:
+---------------
| How do I do this in Lisp? Say we have:
| (format t "paid version")
| How can I omit that at 'load' or 'compile' time?
+---------------

QUICK VERSION [TL;DR]:

Put #-(AND) in front of it:

#-(and) (format t "paid version")

The read-time conditional may be on a separate line,
allowing a rest-of-line comment in a convenient location:

#-(and) ; Turned off in free version.
(format t "paid version")

To re-enable it you only need to change the "-" to a "+":

#+(and) (format t "paid version")


GORY DETAILS:

The canonical way is to use read-time conditional feature
expressions, see CLHS sections:

2.4.8.17 Sharpsign Plus
2.4.8.18 Sharpsign Minus
24.1.2.1 Feature Expressions
24.1.2.1.1 Examples of Feature Expressions

In particular [per style discussions here a decade or so ago],
the fact that the AND and OR feature expressions work like
the logical operators AND and OR when given no additional
arguments -- that is, (AND) is true and (OR) is false --
means that you don't have to make up dummy feature names like
#+IGNORE or #-INCLUDE [which just might conflict with *real*
feature names in some obscure implementations!!]. Instead,
you can always safely use #+(AND) to allow/include the
following form and #-(AND) to disable/exclude the following
form. For example:

'( 1
#+(and) 2
3
#-(and) 4
5)

reads as:

(1 2 3 5)


-Rob

p.s. Some suggested #+(AND) to enable and #+(OR) to disable,
but I find that using #+(AND) and #-(AND) is more mnemonic
since the sense of the +/- goes the right way.

Others have suggested #-(OR) for "on" and #+(OR) for "off"
because they are one character shorter, but it seems weird
and non-intuitive to me that the +/- goes the wrong way.

p.p.s. I confess that I myself use an even *shorter* convention
when debugging my own private code, which is #-+ for "on" and
#+- for "off" [it may take a moment to see why this works -- it
assumes that there are never features named "+" or "-"], with the
mnemonic that #-+ is a "rising edge" [think of it as a waveform]
to switch something "on" while #+- is a "falling edge" to switch
something "off":

'(1 #-+ 2 3 #+- 4 5) ==> (1 2 3 5)

This has the nice property that "on" & "off" can be swapped
by simply swapping the "+-" or "-+" characters.

But for public/shared code I still recommend [and use]
#+(AND) and #-(AND), since they are marginally less obscure.

-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw...
San Mateo, CA 94403

Pascal J. Bourguignon

7/28/2015 5:21:00 PM

0

rpw3@rpw3.org (Rob Warnock) writes:

> Jeremy Smith <jeremy@decompiler.org> wrote:
> +---------------
> | How do I do this in Lisp? Say we have:
> | (format t "paid version")
> | How can I omit that at 'load' or 'compile' time?
> +---------------
>
> QUICK VERSION [TL;DR]:
>
> Put #-(AND) in front of it:

No.

You definitely want #+paid-version
or even #+my-program-configuration:paid-version

Then you can have two scripts:

generate-paid-version.lisp:

(defpackage "MY-PROGRAM-CONFIGURATION" (:use "CL") (:export "PAID-VERSION"))
(setf *features* (remove 'my-program-configuration:paid-version *features*))
(shell "rm -rf ~/.cache/common-lisp/*")
(ql:quickload :my-program)
(save-lisp-image "my-program-paid" :executable t)

generate-demo-version.lisp:

(defpackage "MY-PROGRAM-CONFIGURATION" (:use "CL") (:export "PAID-VERSION"))
(pushnew 'my-program-configuration:paid-version *features*)
(shell "rm -rf ~/.cache/common-lisp/*")
(ql:quickload :my-program)
(save-lisp-image "my-program-demo" :executable t)

You do not go editing manually source files when generating the
products. You want to put that in a makefile and have reproductible
builds!


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

taruss

7/28/2015 11:40:00 PM

0

On Monday, July 27, 2015 at 2:30:24 PM UTC-7, Jeremy Smith wrote:
> Hi Folks,
>
> I'm distributing a Lisp program, as a Clisp binary, and I want to have a
> 'demo' version.
>
> This demo version would be lacking features compared to the paid version.
> ...
> How do I do this in Lisp? Say we have:
>
> (format t "paid version")
>
> How can I omit that at 'load' or 'compile' time?

Well, you really want to do that at compile time (or earlier) otherwise it will
be too late and the code will be distributed.

The read-time macros the others have mentioned are the standard way to do that,
just be sure to only distribute the compiled sources and also make sure you
have everything you want omitted guarded by the read-time conditions.

If you only have the top-level function omitted but include the support, then
anyone with the binary can load it and call the other functions directly
without going through your top-level.

Kaz Kylheku

7/29/2015 12:46:00 AM

0

On 2015-07-27, Jeremy Smith <jeremy@decompiler.org> wrote:
> Hi Folks,
>
> I'm distributing a Lisp program, as a Clisp binary, and I want to have a
> 'demo' version.

By the way, if you're making a closed-source proprietary program
with CLISP, you need to know:

http://www.clisp.org/beta/impnotes/faq.html#faq...

Summary: proprietary programs may not use symbols in CLISP's internal packages;
that requires the GPL. Programs may be shipped as compiled code without
restrictions, but it must be individual .fas files, possibly with a memory
image built out of those same .fas files for convenience (in which case a
Makefile or clear instructions must be given on how to make that memory image
out of the .fas files).