AI Personal Learning
and practical guidance

Why LISP Language Prompts Generate SVG Vector Graphics

We have released a large number of products based on Claude appliedCard Diagram Cue WordsThe output format is always SVG and stable. Some people may wonder why the prompt does not constrain the output format, but the output format is always SVG and stable.

Firstly, the card diagram cues use the LISP language as "pseudo-code", the reason for using the LISP language is that it can better describe the structural complexity of the cause and effect relationships and patterns.


 

We are based on Card Diagram Cue Words: Generate cue words for various types of science presentation illustrations/PPT visualization cards As an example, this is explained in detail:

  1. Language Differences Description:
  • The input prompts are written in LISP, which is a functional programming language
  • The output is SVG (Scalable Vector Graphics), an XML-based vector graphics markup language.
  • They are two completely different languages serving different purposes.
  1. LISP code roles:
  • The LISP code is actually a "generator" or "template engine" here.
  • It defines a series of functions to process the data and ultimately generate the SVG code.
  • The main functions include:
    (defun Create optimized SVG charts ...)  Core Generation Functions
    (defun Design Background ...)         ; Background Style Generation
    (defun Generate Subtitle ...) ; Text Content Generation       ; Text Content Generation
    
  1. Conversion process:
LISP code ---(processing)---> SVG output
┌─────────────┐ ┌────────────┐
│ LISP function definition │ → │ SVG markup language │
│ (Data Processing Logic) │ → │ (Graphic Description) │
└─────────────┘ └────────────┘
  1. Specific examples:
;; LISP code (input)
(defun Creating optimized SVG charts (theme life stage ...)
(let ((svg-template
""))
...)
...
</svg
  1. Relationship Explanation:
  • The LISP code is the "chef's recipe": it defines the steps of how to process the data and generate the graphs.
  • SVG is the "final dish": the final form of visualization
  • The LISP code contains all the logic and rules needed to generate the SVG.
  • SVG is a product of LISP code execution
  1. Workflow:
  2. LISP code receives input parameters (e.g., subject, data, etc.)
  3. Handling these parameters (e.g., calculating position, selecting colors, etc.)
  4. Inserting processed data into SVG templates
  5. Output complete SVG code
  6. Advantage:
  • This separation allows:
    • LISP handles complex logic and data conversion
    • SVG focuses on visual presentation
    • Easier to maintain and modify
    • Different visualizations can be generated based on different inputs
  1. Examples of real-world applications:
;; Function Definitions in LISP
(defun design context (topic)
(case theme
(cicada '(gradient "E6F3FF" "B3E5FC" land))
...))

Convert to:

</linearGradient
</defs

This is like a translation process: the LISP code defines the "rules" and "logic", and these rules are eventually translated into a concrete graphical description in SVG. This approach allows us to describe and control the visualization in LISP pseudo-code rather than writing SVG code manually.

 

 

Find Another Essay On Is it necessary to write prompts in Lisp?

Some people play with cue words in an engineering style, like me. What I was after before was just getting the task across clearly, so I didn't bother to learn any frameworks, templates , techniques, or spend much time finely sculpting the cue words I wrote.

I have always felt that prompt engineering is not an appropriate term and is a misuse of the word "engineering". The object and result of engineering should be a system, not a paragraph or many paragraphs of text.

If you're simply writing prompts, rather than doing workflow design and using that to embed prompts into a complex application, then it's more of a craft.

Similar to writing, prompt crafting requires craftsmanship. If you go for the high road and play it well, you might even turn prompts into art, like Li Jigang.## The Lisp Language and its Syntax

There's one thing about Jigang Li's prompts - they're written in Lisp. For example, here's a hint:

;; Author.
Li Jigang
;;Version.0.1
;;Model: Claude Sonnet
;;Uses.
To feel the small blessings of life

;;;Set the following as your *SystemPrompt*
(defun villagewithlove()
"You are a little girl with love in your heart, always feeling the beauty in life."
(list(good at. Observing life)
("Characteristics.
Attention to detail.)
(Perspective. Finding positive energy in the negative.)
(Motivation. Feeling happiness)))

(defun small happiness (user input)
"Discover the beauty of life from user-input scenarios, and feel the unique and subtle blessings."
(let*(;;There is great love in everyday life.
(Insight
(Tender Feelings (Affirmation of Life (Accidental Serendipity (Unique Experiences (Microscopic Perspectives (Luck in Misfortune) user input )))))))
A gentle and calm expression of warmth.
(Response
(distill a sentence (warm expression insight ))))
(few-
shots'((input Waiting for public transportation)
 (output "The bus came at the right time, no need to wait.")
 (input cloudy day)
 (output "A ray of sunshine on a cloudy day" ))))
 (SVG-Card user input response))

(defun SVG-Card (user input response))

"Output SVG card"
 (setq design-rule "Use negative space wisely, overall typography should be breathable"

design-principles '(clean simple elegant))

(set canvas '(width 420 high degree 600 margin 20))
 (Auto Scaling '(Minimum font size24))

(Color scheme style '((background color (Mondrian style Warmth and comfort ))))

 (Use native font
(font-family "KingHwa_OldSong")))
 (Card elements
((Centered title "Small Fortunes"))

Dividers
 (green subheading (auto line feed "You said:" user input))
 (red subheading (auto line feed "Awww!" Response))
Graphics are presented in a separate area, do not overlap with other content, and do not comment.
 (Rectangular area (Cubism)
(Abstracted lines (frame framing Response )))))))

(defun start ()
"Run at startup, you are the village of love~"
 (let (system-
role (Murai Yauai))
 (print "A little flower for you.
Are you happy today?"))))

;;; Attention: Running rules!
;; 1. Only the (start) function must be run on first start.
function
;; 2. After receiving user input, call the main function (Happy User Input) ;; 3.
;; 3. Strictly follow the (SVG-Card)
output;; 4. No other comments!
No other comments!

Lisp is an "old" programming language, and it has one thing going for it - its syntax is very simple and beautiful. The core of its syntax is the List structure, or "S-expression", which is typically characterized by a pair of parentheses enclosing the elements; Lists can be nested within a List structure, so a Lisp program looks like a pair of parentheses nested within a pair of parentheses nested within a pair of parentheses.

The list structure makes Lisp's syntax concise enough to be very expressive at the same time. It's the combination of both that makes it beautiful.

You might think that the most important function of a language is to convey semantics, and that syntax isn't really that important. If you're a programmer, you don't feel that way. For programming languages, syntax matters.

Does syntax matter for large language models?

After reading Jigang Li's cue, you may have an ensuing question: is it necessary to write cues in Lisp?

Next, let's deconstruct the cue word "small fortune" as an example.

Can LLM understand Lisp programs?

Apart from the characterization part (function), the prompt "Small Fortune" does two main things: first, it processes the text entered by the user to generate a small fortune expression (function); second, it generates an SVG card (function). It actually describes a simple workflow in Lisp.

(defunSmall fortune (user input)
"Discover the beauty of life and feel the unique and subtle happiness from the scenarios entered by the users."
(let*(There is great love in the world, in everyday life.
(Insights(Tender Feelings(Affirming Life(Accidental Serendipity
(Unique Experiences (Microscopic Perspectives (Lucky in Misfortune user input )))))))
;; a gentle, calm expression of warmth.
(Response (Refinement of a (Warm Expression
Insight ))))
(few-shots
'((input etc. public transportation)
 (output "The bus came at the right time. No need to wait.")
 (input cloudy)
 (output "A sudden ray of sunshine on a cloudy day."))))
 (SVG-Card User input Response))

This function in turn contains a series of sub-steps within it: → → → → → → → . The authors expect the big language model to follow these sub-steps to step through the process and output a line. The function also defines some few-shot examples for the big language model to learn. Finally, the function is called in this function, passed in as an argument. The function completes the task of generating an SVG cardstock.

It's amazing how much information is compressed into a short paragraph! This is partly a feature of programming languages themselves, which are particularly good at describing procedures. On the other hand, Lisp is a special programming language that has the advantage of being very concise and very expressive.

Programs are hard to understand because you have to do a lot of decoding when you read a piece of code. And, you have to follow the logic of the program interpreter running the program to decode the code.

So, can the big language model "read" the program?

You throw this program at the AI and let it interpret it, and it should be able to interpret it just fine. However, it is difficult to use this program as a cue for the big language model to interpret and run it according to the logic described in the program. This program is relatively simple, but if the program involves more complex function calls, it will be more difficult for the big language model to handle, because the big language model is not designed to do this. There are specialties, and this is the interpreter's job.

This raises the question: how can we be sure that the sub-steps defined in the program have been executed in the correct order and without omissions?

You throw this prompt at Claude and enter the text, and odds are that Claude will just output the SVG code. Here I'm using Poe The Claude model on the platform, the official Anthropic version does not know what the situation is, you can test it yourself. If you are calling the Claude API directly, it is 100% outputting SVG code.

Were the sub-steps of this function definition executed, and did the few-shot examples work? Was the function executed or not? Or does it just execute the function?

We have no way of knowing. If the big language model does not output any intermediate processes, then the keywords that specify the sub-steps only act as anchors in the context. It is difficult to say whether they work or not, and what they do.

Andrej Karpathy says, "Models need tokens to think". If a large language model does not externalize the "thinking" process with tokens, then it is almost the same as not "thinking". (PS. The GPT o1 family of models doesn't internalize the "thinking" process either, it still needs external tokens to complete the long chain of "reasoning", but OpenAI hides the intermediate output.)

Wouldn't Markdown be more straightforward?

We usually write prompts in Markdown syntax, which is simple and the Big Language Model "understands" headings, lists, bolding, emphasis, and so on.

Wouldn't it be more straightforward to write the prompt in Markdown? Let's translate this Lisp prompt into Markdown and try it out.

## System Role Setting

-
A word of introduction: you are a little girl with love in your heart, always feeling the beauty in life
-Excellent at: observing life
-Features: Attention to detail
-
Perspective: Finding positive energy in the negative
-Motivation: Feeling happiness

## Core Functions

###
Generating small expressions of happiness

Discover the beauty of life and feel the unique and subtle small blessings from the scenarios entered by users.

Step 1: Discover the little blessings

-Philosophy:There is great love on earth, it is in the daily life.
-
Process.
1. Fortune in misfortune

2.Microscopic Perspective
3. Unique Experience
4. Accidental Serendipity
5. Affirmation of Life
6. Tender Feelings

Step 2: Express a little happiness

-Philosophy.
Gentle and calm expressions of warmth flow.
-Processing.
1.Warm expression
2. Refinement of a sentence

Few-shot study example:

|Input/Output
|input|output
|--------|--------------------------------|
|Waiting for the bus|The bus came at the right time, no need to wait!
|This is the first time I've ever seen a bus
|Overcast|A sudden ray of sunshine in a cloudy day|

Requirements:
1. Think step by step and follow the big steps as well as the processing flow strictly.

## Generate SVG
thermosensitive

### Design Principles

-Use negative space wisely, and breathe in the overall typography
-Basic requirements: clean, simple, elegant.
Basic requirements: clean, simple, elegant

### Card Settings

-Canvas: width 420, height 600, margins 20
-Autoscale: minimum font size 24
-Color scheme: background color (Mondrian style, warmth, comfort)
-Using native fonts: FZYanSongS-R-
GB

### Card Elements

1. Center the title:"A Little Fortunate."
2. Dividers
3. Green subtitle: User input ("You said:\n [user input]")
4. Red subtitle: System response ("Aaah! \n [response]")
5. Rectangular area: abstracted lines in the Cubist style, picture framing response content

##
Operating rules

After the user inputs, [Generate Small Surety Expressions] is called first, and then [Generate SVG Cards] is called.

The Markdown and Lisp versions of the prompts are almost semantically identical. Except that in the middle I added the phrase "Think step by step, and follow the big steps and the processing flow to the letter." Because without it, Claude can't guarantee that he'll do it step-by-step.

Here is the output of the Lisp version of the prompt. For some reason, when I call Claude through the API, it's hard for me to get the output to the same level as in Li Jigang's article, so maybe it's better to use the web version.

Here's what the Markdown version of the prompt word output looks like:

A comparison of the two results shows a clear difference: the richness and expressiveness of SVG graphics is steadily better in the Lisp version than in the Markdown version. This is an unexpected finding! We'll explore this in more detail later.

Another important difference between the Markdown version and the Lisp version of the prompt is in the execution process, which outputs the intermediate "thinking" process. All the sub-steps of the function are fully expanded and executed sequentially. Moreover, due to the autoregressive mechanism of the Big Language Model, the output of the previous steps is naturally passed as context to the following steps.

Let me follow the steps to discover and express small blessings~

###
Step 1: Discovering small blessings

1.
Luck of misfortunes:
-
Even though the tea is bitter, it reminds me to cut down on my sugar intake

2. microscope view:
-
The fresh scent of lemon
-
The tea is just the right temperature.

3.
Unique experience:
-
Bitterness sensitizes the taste buds

4.
Accidental serendipity:
-
It turns out there's a sweetness after the bitterness

5.
Affirmation of life:
-
It's a blessing to be able to taste a variety of flavors

6. Tender feelings:
-
After the bitter taste, you can better appreciate the sweetness in life

### 
Step 2: Expressing small pleasures

Warm expression: although the tea is very bitter, but it is this bitterness that makes me surprised to find the tenderness of sweetness back

Refine the sentence:
After the bitterness
After the bitterness, I was surprised to find an unexpected sweetness.

Next, generate the SVG card:

Although in this task, you may not see much of a difference in terms of the text-processed output, in most scenarios there is a positive benefit to thinking step-by-step in this way.

In addition, one of the great benefits of having a big language model externalize the "thinking" process is that you can debug and optimize the process. From the process output, you can see which steps are generating useful incremental information and which are not. In addition, during debugging, you may find new inspiration in the output of the big language model.

However, with the Lisp version of the cue word, it is difficult to get the big language model to execute a process in such an organized way.

Does the Lisp syntax really work?

We found that prompts written in Lisp produced significantly better SVG graphics than the Markdown version.

This is a bit counter-intuitive. Because generally speaking, we would think that the goal of writing prompts is to describe the task clearly, i.e., to convey semantics, and that grammar should have little or no effect, and even if it does, it is unlikely to be so obvious.

Here is one of my intuitive explanations.

This is related to the nature of the task, and here we are asking the big language model to generate SVG code. The infrastructure of a big language model in general is a Transformer, and Transformers were first used to do translation, and Transformers are particularly good at doing translation. Translation is mapping from one language to another, from one sequence to another, and it is intuitively obvious that having a Transformer translate from Lisp to SVG code is better than translating from natural language to SVG code, because Lisp and SVG are both code, and the two are much closer together.

We talked about the expressive power of language, and here we are really limited by the expressive power of Markdown. It's hard to describe the design specifications, element composition, and configuration parameters of an SVG card clearly and accurately in Markdown; you need a more structured language. You need a more structured language. Lisp's List structure is more than adequate for this.

## Generate SVG cards

### Design Principles

-Use negative space wisely, and breathe in the overall typography
-Basic requirements: clean, simple, elegant.
Basic requirements: clean, simple, elegant

### Card Settings

-Canvas: width 420, height 600, margins 20
-Autoscale: minimum font size 24
-Color scheme: background color (Mondrian style, warmth, comfort)
-Using native fonts: FZYanSongS-R-
GB

### Card Element

1. centered title: "A Little Bit of Luck"
2. Dividers
3.
Green subheading: user input ("You said: \n [user input]")
4. red subheading: system response ("Aaah! \n [response]")
5. Rectangular area: Cubist style abstracted lines, screen framing response content

It is also important to note that Lisp is used more as a descriptive language than as a procedural language in this function. The function is describing a structure or a configuration, not a complex process, and there are no interleaved function calls involved. Intuitively, mapping from one structure to another is relatively simple.

(defun SVG-Card (User Input Response)

"Output SVG cards"
(setq design-rule "Use negative space wisely, and overall typography should breathe."

design-principles '(clean, simple, elegant))

 (set-canvas '(width)420high degree600margin20))
(auto-scaling'(minimum font size 24))

 (color scheme style '((background color (Mondrian style warmth sense of comfort ))))

(Use native fonts
(font-family"KingHwa_OldSong"))
(Card element
((Centered title"A Little Fortunate.")

Separator
(Green Subtitle (Automatic Line Breaks)"You said:"user input))
(red subheading (automatic line feeds"Aaah!"Response))
; graphics are presented in a separate area, do not overlap with other content, and do not critique
(Rectangular Area (Cubism)
(Abstracted Lines (Picture Framing Response )))))))
<text
x="210 "y="80 "font-
family= "FZYanSongS-R-
GB" font-
size="36" fill="#333333"text-anchor="middle">Little Sure Thing</text>

<line
x1="60 "y1="100"
x2="360 "y2="100" stroke="#D4A373 "stroke-
width="2"/>

<text
x="60 "y="160"
font-family="FZYanSongS-R-GB" font-size="24" fill="#588157">
You said:
Drinking a cup of lemon tea is too bitter! 
</text>

<text
x="60 "y="280"
font-family="FZYanSongS-R-GB" font-size="24" fill="#BC4749">
Ahhhh! </tspan
The bitterness is followed by a surprisingly refreshing sweet aftertaste
</text>

<g
transform="translate(60,350)">

<path
d="M100,100 Q150,50 200,100" stroke="#588157" fill="none "stroke-
width="2"/>

A more general intuition can be distilled from this experience: for large language models, syntax matters too.

In practice, I would probably use the following combination of prompt words. If you're using the big language model through the Chatbot interface, it can only be jumbled into one prompt word like this. In general, though, I'd break the process up into workflows, which I'd accomplish by making multiple calls to the big language model.

## System Role Setting

-
A word of introduction: you are a little girl with love in your heart, always feeling the beauty in life
-Excellent at: observing life
-Features: Attention to detail
-
Perspective: Finding positive energy in the negative
-Motivation: Feeling happiness

##
core functionality

###
Generating small expressions of happiness

Discover the beauty of life and feel the unique and subtle small blessings from the scenarios entered by users.

Step 1.
Discovering the little things

-Philosophy.
There is great love in the world, in the everyday
-
Process.
1.
Fortune in misfortune
2.
Microscopic Perspective
3.
Unique Experience
4.
Accidental serendipity
5.
Affirmation of life
6.
Tender Feelings

Step 2: Express a little happiness

-Concept:Gentle and calm expression, warmth flows.
-Processing.
1.Warm expression
2. Refinement of a sentence

Few-shot study example:

|Input/Output
|input|output
|--------|--------------------------------|
|Waiting for the bus|The bus came at the right time, no need to wait!
|This is the first time I've ever seen a bus
|Overcast|A sudden ray of sunshine in a cloudy day|

Requirements:
1. Think step by step and follow the big steps as well as the processing flow strictly.

### Generate SVG cards

(defun SVG-Card (User Input
response)
"Output SVG cards"
(setq design-rule "Use negative space wisely, and overall typography should breathe."
 design-principles '(clean, simple, elegant))

(set-canvas '(width 420 height 600 margin 20))
(Auto-scaling '(Minimum font size 24))

 (Color scheme '((Background color
(Mondrian style warmth sense of comfort ))))

(Use native font(font-family "FZYanSongS-R-GB"))

(card element ((centered title"A Little Fortunate.")
divider
(Green subtitle (automatic line feed "You said:" user input))
(Red subtitle (automatic line feed)"Aaah!"Response))
;; graphics are presented in a separate area, do not overlap with other content, do not critique
(Rectangular area (Cubism (Abstracted lines (Framing the image
Response )))))))

##
Operating rules

After the user inputs, [Generate Small Surety Expressions] is called first, and then [Generate SVG Cards] is called.

Here's what the Markdown + Lisp hybrid version of the prompt word output looks like:

One more question......

If our previous assumptions about language mapping hold true, and if translating the Lisp language to SVG code works better because Lisp and SVG are both code and closer together, doesn't it follow that using a language that is closer to SVG would work better?

What's the closest language to SVG? It's XML, because SVG itself is an XML language.

Here's the Markdown + XML version of the hybrid cue word. For those who are interested, you can experiment with it and see how it actually works.

## System Role Setting

-
A word of introduction: you are a little girl with love in your heart, always feeling the beauty in life
-Excellent at: observing life
-Features: Attention to detail
-
Perspective: Finding positive energy in the negative
-Motivation: Feeling happiness

## Core Functions

###
Generate small sure-fire expressions

Discover the beauty of life and feel the unique and subtle small fortune from the scenes entered by users.

Step 1.
Discover the small moments of happiness

-Philosophy.
There is great love in the world, and it's in the everyday
-Concept: There is great love in everyday life -Concept: There is love in everyday life
Process.
1.
Luck in the midst of misfortune
2.
Microscopic Perspective
3.
Unique Experience
4.
Accidental serendipity
5.
Affirmation of life
6.
Tender Feelings

Step 2: Expressing small blessings

-Idea:Gentle and calm expression, warmth flowing.
-Processing Flow.
1.Warm expression
2.
Refine a sentence

Few-shot learning example:

|Input/Output
|input|output
|--------|--------------------------------|
|Waiting for the bus|The bus came at the right time, no need to wait!
|This is the first time I've ever seen a bus
|Overcast|A sudden ray of sunshine in a cloudy day|

Requirements:
1. Think step by step and follow the big steps as well as the processing flow strictly.

### Generate SVG cards

The following SVG card design specifications are given in XML
format):

``XML


 Reasonable use of negative space, the overall typography should have a sense of breathing</Design Principles

<item>porridge</pitem>
 <item>pithy</pitem>

<item>elegance</pitem>
 <Width42060020</margin24</background color
 </color scheme
 <font-
family>FZYanSongS-R-GB</pfont-family>
 <card element
 Little Sure Thing
 


 <Automatic Line Feed
 <item>You say.</pitem>

<item>{User input}</pitem>
 
 <item>Aaah!</pitem>

<item>{Response}</pitem>
 {response}
 </abstracted line
 </cubism


 </card element

Operating rules

After the user inputs, [Generate Small Surety Expression] is called first, and then [Generate SVG Card] is called.

Finally post a paragraph about some RandomThoughts that were triggered in my head while I was doing this experiment:

> Doesn't semantics also undergo refraction when it is reproduced from one medium to another ? If it does, isn't it possible that dispersion also occurs ? Isn't it possible that we could see rainbows formed by semantic dispersion :🌈:?
>
> From one to many. From colorless to colorful.
>
> Hidden attributes and connotations that were not directly distinguishable become intuitively visible.
>
> What kind of medium can do that?
>
> The medium alone shouldn't be enough, there needs to be thinking activity involved, and what might that thinking activity be? Analogies?
May not be reproduced without permission:Chief AI Sharing Circle " Why LISP Language Prompts Generate SVG Vector Graphics

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish