Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 631693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:59:38+00:00 2026-05-13T19:59:38+00:00

Forgive the duplicate question. I’d like to see this solved in Emacs Lisp too,

  • 0

Forgive the “duplicate” question. I’d like to see this solved in Emacs Lisp too, and if I just tagged it for both topics, I probably would have only gotten one answer. The Emacs answer should be sufficiently different that it’s probably worthwhile to have it.

I want to teach myself Spanish and I’ve got several word lists like
the data show below. How can I generate a quiz from the data that
looks like this?

amarillo?  [ ] blue    [ ] yellow  [ ] gray   [ ] pink
azul?      [ ] red     [ ] blue    [ ] green  [ ] orange
 .
 .
 .
verde?     [  ] purple [ ] gold   [ ] green   [ ] black

The idea is to randomly include the answer with 3 randomly chosen
incorrect answers. Ideally, the incorrect answers would not be too
repetitive.

amarillo|yellow
azul|blue
blanco|white
dorado|golden
gris|gray
marrón|brown
naranja|orange
negro|black
oro|gold
púrpura|purple
rojo|red
rosa|pink
verde|green
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:59:38+00:00Added an answer on May 13, 2026 at 7:59 pm

    Ok, so I’m assuming that you have the input in a file opened in an Emacs buffer.

    (defun insert-quiz (a-buffer)
      (interactive "bBuffer name: ")
      (let* ((question-pairs (split-string (with-current-buffer a-buffer (buffer-string))))
             (quiz-answers (mapcar (lambda (x) (cadr (split-string x "|"))) question-pairs)))
        (insert 
         (apply #'concat 
                (mapcar
                 (lambda (x)
                   (let ((q-pair (split-string x "|")))
                     (make-question (car q-pair) (answers-list quiz-answers (cadr q-pair)))))
                 question-pairs)))))

    insert-quiz is an interactive function that takes a buffer name, and uses the stuff in that buffer to generate a quiz for you, then insert that quiz at point as a side-effect. It calls some smaller functions which I’ll explain below.

    (defun make-question (question answers)
      (apply #'format
             "%-16s[ ] %-16s[ ] %-16s[ ] %-16s[ ] %s \n"
             (append 
              (list (concat question "?"))
              answers)))

    make-question takes a question and a list of answers, and formats them as one line of the quiz.

    (defun answers-list (quiz-answers right-answer)
      (replace (n-wrong-answers quiz-answers right-answer)
               (list right-answer)
               :start1 (random 3)))

    answers-list takes a list of all possible answers in the quiz, and the right answer and uses n-wrong-answers to create a list of four answers, one of which is the correct one.

    (defun n-wrong-answers (answer-list right-answer &optional answers)
        (if (= 4 (list-length answers))
            answers
          (n-wrong-answers 
           answer-list 
           right-answer 
           (add-to-list 'answers (random-wrong-answer answer-list right-answer)))))

    n-wrong-answers takes a list of all possible answers in the quiz, and the right answer, then uses random-wrong-answer to return a list of four unique incorrect answers.

    (defun random-wrong-answer (answer-list right-answer)
      (let ((gen-answer (nth (random (list-length answer-list)) answer-list)))
        (if (and gen-answer (not (string= gen-answer right-answer)))
            gen-answer
            (random-wrong-answer answer-list right-answer))))

    Finally, at the lowest level, random-wrong-answer takes a list of all possible answers in the quiz, and returns a single wrong answer.

    After you load the above functions into Emacs, use M-x insert-quiz and type the name of the buffer you have your input loaded into (you’ll get tab completion). It wouldn’t be too difficult to change the insert-quiz function so that it takes a filename rather than an open buffer-name.

    The input you list above will yield:

    amarillo?               [ ] yellow          [ ] orange          [ ] gray            [ ] red 
    azul?                   [ ] gold            [ ] purple          [ ] blue            [ ] orange 
    blanco?                 [ ] pink            [ ] red             [ ] white           [ ] black 
    dorado?                 [ ] yellow          [ ] golden          [ ] red             [ ] orange 
    gris?                   [ ] red             [ ] pink            [ ] gray            [ ] green 
    marrón?                 [ ] brown           [ ] yellow          [ ] white           [ ] golden 
    naranja?                [ ] orange          [ ] gold            [ ] black           [ ] golden 
    negro?                  [ ] pink            [ ] black           [ ] blue            [ ] white 
    oro?                    [ ] red             [ ] gold            [ ] purple          [ ] brown 
    púrpura?                [ ] purple          [ ] orange          [ ] gray            [ ] black 
    rojo?                   [ ] gray            [ ] red             [ ] black           [ ] pink 
    rosa?                   [ ] red             [ ] green           [ ] pink            [ ] yellow 
    verde?                  [ ] green           [ ] purple          [ ] red             [ ] brown 
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this question is too silly. I am making a webpage on
Forgive me if this is a repeat question. I've searched StackOverflow and did not
(THIS IS A DUPLICATE, I FORGOT A TAG, PLEASE FORGIVE) I'm writing a small
Forgive a newbie, I don't even know how to ask this question properly: I
Forgive me if this is a duplicate, but it's a minor issue for me
Forgive me if this is a slight mis-use of the system, but I'd like
Forgive me if this question is stupid, however what is the point of the
Forgive me if this question is very vague Some time back i faced this
Forgive me if this is a newbie question: I've got a menu set to
Forgive me for such a basic question; this is (I suppose) more of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.