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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:51:39+00:00 2026-05-26T16:51:39+00:00

I am trying to find the minimum value of a list (as a learning

  • 0

I am trying to find the minimum value of a list (as a learning experience, so without min).

My approach is the following:

minimo([X], X).
minimo([X,Y|Tail], N):-
    (X > Y, minimo([Y,Tail], Y));
    (X <= Y, minimo([X,Tail], X)).

This gives me the following error:

Syntax error: Operator expected

So my questions are:

  • What is causing the syntax error?
  • I will try it myself once that is fixed if it actually gives the correct value back, but would this actually be a correct approach?

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-05-26T16:51:39+00:00Added an answer on May 26, 2026 at 4:51 pm

    There are several bugs in your program:

    1. as pointed out by Joe Lehmann, there is no '<='/2. It must be '=<'/2.

    2. when you call minimo/2 recursively, you construct the lists wrong. Instead of [Y,Tail] use [Y|Tail]. Otherwise, you get a list with a list as second element.

    3. you bind the second argument of the recursive call of minimo/2 to Y or X. Instead it must be bound to N. Otherwise, your N will never be instantiated.

    You can improve your program further by adding cuts or using if-then-else ('->' + ;):

    minimo([X], X) :- !.
    minimo([X,Y|Tail], N):-
        ( X > Y ->
            minimo([Y|Tail], N)
        ;
            minimo([X|Tail], N)
        ).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, this is very confusing... i am trying to find the minimum of
I'm trying to write a program that would find the minimum spanning tree. But
Im trying to find a regular expression that matches this kind of URL: http://sub.domain.com/selector/F/13/K/100546/sampletext/654654/K/sampletext_sampletext.html
Im trying to get the min value in a column in the row of
I'm trying to find minimum of an array. The array contain Nodes - a
I'm trying to find the minimum number in a array using Thrust and CUDA.
Oracle version : 10g I'm trying to use the MIN function to find the
I am trying to find the minimum and maximum values for the continuous while
I'm trying to use boost's prim's algorithm to find the minimum spanning tree using
I've been trying to find the optimal solution to the following (interesting?) problem that

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.