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 8259283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:49:25+00:00 2026-06-08T02:49:25+00:00

I already have the following code: atom_length(Var, Len) :- length(Var, Len). I wanna construct

  • 0

I already have the following code:

"atom_length(Var, Len) :- length(Var, Len)."

I wanna construct a predicate atom_lengths/2 that does the same thing with a list of atoms:

?-  atom_lengths([one, two, three, four], [3, 3, 5, 4]).
true.
?-  atom_lengths([one, two, three, four], LS).
LS = [3, 3, 5, 4].
?-  atom_lengths([], LS).
LS = [].

How to write “atom_lengths”??
Thanks in advance!

  • 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-06-08T02:49:27+00:00Added an answer on June 8, 2026 at 2:49 am

    You cannot use length/2 to compute the length of an atom.
    You can however first convert each atom to a list of characters with atom_chars/2 and then use length/2 to get its length:

    atom_lengths([], []).
    atom_lengths([Atom|Atoms], [Length|LAtoms]):-
      atom_chars(Atom, L),
      length(L, Length),
      atom_lengths(Atoms, LAtoms).
    

    Test:

    ?- atom_lengths([one, two, three, four], LS).
    
    LS = [3,3,5,4]
    

    Instead of using the pair atom_chars/2-length/2 you could also use ISO builtin predicate atom_length/2:

    atom_lengths([], []).
    atom_lengths([Atom|Atoms], [Length|LAtoms]):-
      atom_length(Atom, Length),
      atom_lengths(Atoms, LAtoms).
    

    or using findall/3:

    atom_lengths(Atoms, LAtoms):-
      findall(Length, (member(Atom, Atoms), atom_length(Atom, Length)), LAtoms).
    

    As suggested by commenter, a better idiom would be to use maplist/3:

    atom_lengths(Atoms, LAtoms):-
      maplist(atom_length, Atoms LAtoms).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've have already implemented pagination using the following code: public Paginacao<Anuncio> consultarPaginado(int pagina, Integer
I'm doing something similar to the following code. I have already gone through AddtoStructFunction()
I have the following code that I am working on for my college assignment.
I have the following code in a static class called Methods that is archived
I have the following code: public ActionResult Foo() { var a = a; return
I have to following code: http://www.nomorepasting.com/getpaste.php?pasteid=22987 If PHPSESSID is not already in the table
I have the following code that gets initialized as a static variable in a
I have the following code which I want to use to make sure that
The following code is a test to test what I have already done with
I have the following Problem: I have already opened a JQuery dialog and I

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.