unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* GPT-4 knows Guile! :)
@ 2023-03-17 16:01 Mikael Djurfeldt
  2023-03-17 17:25 ` Mikael Djurfeldt
  0 siblings, 1 reply; 23+ messages in thread
From: Mikael Djurfeldt @ 2023-03-17 16:01 UTC (permalink / raw)
  To: guile-user, guile-devel; +Cc: Mikael Djurfeldt

[-- Attachment #1: Type: text/plain, Size: 4314 bytes --]

Mikael: Let's write a scheme program which randomly makes names by
combining two words from a list.

To write a Scheme program that generates random names by combining two
words from a list, you can use the following code:

scheme

(import (scheme random)) ; Import random number generation functions

(define word-list '("Alpha" "Beta" "Gamma" "Delta" "Epsilon" "Zeta"
"Eta" "Theta" "Iota" "Kappa"))

(define (random-word lst)
  (list-ref lst (random (length lst))))

(define (random-name)
  (string-append (random-word word-list) (random-word word-list)))

(random-name)

In this program, we:

   1. Import the random number generation functions from the (scheme random)
   library.
   2. Define a word-list containing words that will be used to generate
   random names.
   3. Create a function random-word that takes a list as an argument and
   returns a random element from that list.
   4. Create a function random-name that combines two random words from the
   word-list using string-append.
   5. Call random-name to generate a random name.

You can run this code in a Scheme interpreter or REPL (Read-Eval-Print
Loop) to generate random names.
[image: mikael@djurfeldt.com]
Mikael: Great! Can you adapt it for Guile scheme?

Sure! Here's the adapted code for Guile Scheme:

scheme

(use-modules (ice-9 random)) ; Import random number generation
functions for Guile

(define word-list '("Alpha" "Beta" "Gamma" "Delta" "Epsilon" "Zeta"
"Eta" "Theta" "Iota" "Kappa"))

(define (random-word lst)
  (list-ref lst (random (length lst))))

(define (random-name)
  (string-append (random-word word-list) (random-word word-list)))

(random-name)

In this Guile Scheme version, we:

   1. Replace the (import (scheme random)) statement with (use-modules
   (ice-9 random)) to import random number generation functions in Guile
   Scheme.
   2. The rest of the code remains the same as the original Scheme version.

You can run this code in a Guile Scheme interpreter or REPL to generate
random names.
[image: mikael@djurfeldt.com]
Mikael: Now let's use the words doodle, puck, bongo, foo, bar zoinc instead.

Here's the Guile Scheme code using the new words you provided:

scheme

(use-modules (ice-9 random)) ; Import random number generation
functions for Guile

(define word-list '("doodle" "puck" "bongo" "foo" "bar" "zoinc"))

(define (random-word lst)
  (list-ref lst (random (length lst))))

(define (random-name)
  (string-append (random-word word-list) (random-word word-list)))

(random-name)

The only change made to the original code is updating the word-list with
the new words you've provided. The rest of the code remains the same. You
can run this updated code in a Guile Scheme interpreter or REPL to generate
random names using the new words.
Mikael: Can you execute (random-name)?

As an AI text-based model, I am unable to directly execute code in a REPL
environment. However, I can help you understand how to run the provided
code.

To run the provided Guile Scheme code and execute (random-name), you can
follow these steps:

   1.

   Install Guile on your computer if you haven't already. You can find
   installation instructions here:
   https://www.gnu.org/software/guile/download/
   2.

   Copy and paste the provided code into a text editor, and save it as a
   file named random-name.scm.
   3.

   Open a terminal or command prompt, and navigate to the directory where
   you saved the random-name.scm file.
   4.

   Run the following command in the terminal or command prompt: guile -s
   random-name.scm

This command will execute the Guile Scheme code in the random-name.scm file
and print a random name using the words from the word-list. Each time you
run the command, you will get a new random name as the output.[image:
mikael@djurfeldt.com]
Mikael: Can you give one example of how the result would look like?

Certainly! When you execute the provided Guile Scheme code using the given
word list, you may get different random names each time you run it. Here's
one possible example of a random name generated using the words in the
word-list:

doodlebongo

In this example, the program has combined the words "doodle" and "bongo" to
create a new random name. Keep in mind that you will get different results
each time you run the program, as the name generation is random.

[-- Attachment #2: Type: text/html, Size: 22369 bytes --]

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

end of thread, other threads:[~2023-03-19 21:22 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 16:01 GPT-4 knows Guile! :) Mikael Djurfeldt
2023-03-17 17:25 ` Mikael Djurfeldt
2023-03-17 19:09   ` Damien Mattei
2023-03-17 19:28     ` Damien Mattei
2023-03-18  7:03   ` tomas
2023-03-18  7:55     ` Mikael Djurfeldt
2023-03-18  8:11       ` Mikael Djurfeldt
2023-03-18  8:14       ` tomas
2023-03-18  8:22         ` Mikael Djurfeldt
2023-03-18  8:36           ` tomas
2023-03-18  8:41             ` Mikael Djurfeldt
2023-03-18  8:46               ` tomas
2023-03-18  8:58                 ` Mikael Djurfeldt
2023-03-18  9:03                   ` Mikael Djurfeldt
2023-03-18  9:23                     ` Damien Mattei
2023-03-18  9:47                     ` Mikael Djurfeldt
2023-03-18 10:01                     ` tomas
2023-03-18 10:49                       ` Stefan Israelsson Tampe
2023-03-18 11:43                         ` Mikael Djurfeldt
2023-03-19  8:46                         ` tomas
2023-03-18  8:34         ` Mikael Djurfeldt
2023-03-18  8:21     ` Dr. Arne Babenhauserheide
2023-03-19 21:22       ` tomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).