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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:22:02+00:00 2026-06-17T04:22:02+00:00

I want to multiply two lists, where I take the left list and multiply

  • 0

I want to multiply two lists, where I take the left list and multiply it by each element of
the right list.

For example:

?- multLists([3,4,2], [4,7,8], R).
R = [[12,16,8],[21,28,14],[24,32,16]].

For that I wrote a helper predicate that takes a list and multiplies it
by a single scalar:

multListElem([], _, _).
multListElem([H|T], Result, Elem) :- 
    multListElem(T, W, Elem),
    Z is H*Elem,
    Result = [Z|W].

But now, when I run ?- multListElem([1,2,3], X, 3).
I get:

1 ?- multListElem([1,2,3], X, 3).
X = [3, 6, 9|_G1840].

What is that weird tail _G1840?

  • 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-17T04:22:03+00:00Added an answer on June 17, 2026 at 4:22 am

    The bug is here: multListElem([],_,_). When the first list is empty, the result is empty, so you must write multListElem([],[],_).

    When you work with lists, you can use functional idioms like
    maplist:

    multLists(L1, L2, R) :-
        maplist(mult_one_list(L1), L2, R).
    
    mult_one_list(L1, Elem, R) :-
        maplist(mult_2_numbers(Elem), L1, R).
    
    mult_2_numbers(V1, V2, R) :-
        R is V1 * V2.
    

    maplist applies the first argument to each element of each list (passed to it as an argument).

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

Sidebar

Related Questions

I want to perform an element wise multiplication, to multiply two lists together by
I want to delete multiple records at once. I have two tables, one that
I have two models, Leads and courses, Leads HABTM courses. I want to list
I have two separate Python List that have common key names in their respective
I want to compare two price lists for different years from a supplier. I
I have a product feed that lists clothing items multiple times, once each for
I have two HTML select list and i want to remove all the elements
I want to take a list of directory hierarchies and flatten them into a
Here are two functions that split iterable items to sub-lists. I believe that this
I want to sort multiple and multilevel unordered lists. An example: <!DOCTYPE html> <html>

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.