Interview Quizz Logo

 
  • Home
  • About Us
  • Electronics
  • Computer Science
  • Physics
  • History
  • Contact Us
  • ☰
  1. Computer Science
  2. Programming Technologies
  3. Mercury Interview Question with Answer

Mercury Questions and Answers for Viva

Frequently asked questions and answers of Mercury in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best Mercury Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download Mercury FAQs in PDF form online for academic course, jobs preparations and for certification exams .

Intervew Quizz is an online portal with frequently asked interview, viva and trivia questions and answers on various subjects, topics of kids, school, engineering students, medical aspirants, business management academics and software professionals.




Interview Question and Answer of Mercury


Question-1. How do you debug Mercury programs?

Answer-1: Using mdb (Mercury Debugger) or tracing.



Question-2. Why use Mercury over Prolog?

Answer-2: Mercury offers better performance, static typing, and explicit determinism handling.



Question-3. What is Mercury?

Answer-3: Mercury is a logic-functional programming language designed for high-performance declarative programming.



Question-4. Who developed Mercury?

Answer-4: Mercury was developed at the University of Melbourne by Zoltan Somogyi and his team.



Question-5. What programming paradigms does Mercury support?

Answer-5: Mercury supports logic, functional, and declarative programming paradigms.



Question-6. How is Mercury different from Prolog?

Answer-6: Mercury enforces strong static typing, determinism, and has better optimization compared to Prolog.



Question-7. What is the primary goal of Mercury?

Answer-7: To provide a high-performance and reliable declarative programming language with strong typing and determinism.



Question-8. What type of typing does Mercury use?

Answer-8: Mercury uses strong static typing.



Question-9. What is a mode in Mercury?

Answer-9: A mode defines the input/output behavior of a predicate, specifying which arguments must be given and which are computed.



Question-10. How does Mercury handle determinism?

Answer-10: Mercury uses determinism categories like det, semidet, multi, nondet, and erroneous to specify behavior.



Question-11. How do you declare a predicate in Mercury?

Answer-11: Using :- pred followed by the predicate signature, e.g., :- pred factorial(int, int).



Question-12. How do you implement a predicate in Mercury?

Answer-12: Using :- mode and :- pred, then defining it with :- implementation.



Question-13. What is the purpose of :- mode in Mercury?

Answer-13: It specifies how arguments should be used (input/output).



Question-14. What are the common modes in Mercury?

Answer-14: in, out, di (destructive input), and uo (unique output).



Question-15. How does Mercury handle higher-order programming?

Answer-15: Mercury supports higher-order functions using function types and lambda expressions.



Question-16. What is a functional type in Mercury?

Answer-16: A functional type allows defining functions, e.g., :- func square(int) = int.



Question-17. How do you write a recursive function in Mercury?

Answer-17: Similar to other functional languages, using base and recursive cases.



Question-18. What is determinism in Mercury?

Answer-18: It defines the number of valid solutions a predicate can have.



Question-19. What determinism type ensures exactly one solution?

Answer-19: det (deterministic) ensures exactly one solution.



Question-20. What determinism type allows zero or one solutions?

Answer-20: semidet (semi-deterministic) allows either zero or one solutions.



Question-21. What determinism type allows multiple solutions?

Answer-21: multi (multi-deterministic) allows multiple solutions.



Question-22. What determinism type allows failure?

Answer-22: nondet (non-deterministic) can succeed multiple times or fail.



Question-23. How do you declare a list in Mercury?

Answer-23: Using list(T), e.g., list(int).



Question-24. How do you construct a list in Mercury?

Answer-24: Using `[Head



Question-25. How do you append two lists in Mercury?

Answer-25: Using list.append(List1, List2).



Question-26. How do you perform pattern matching in Mercury?

Answer-26: Using `Head



Question-27. How do you define a user-defined type in Mercury?

Answer-27: Using :- type, e.g., :- type color ---> red ; green ; blue.



Question-28. What is a fact in Mercury?

Answer-28: A fact is a rule with no body, used to define static knowledge.



Question-29. What is a rule in Mercury?

Answer-29: A rule is a clause defining a predicate with conditions.



Question-30. How do you define a conditional statement in Mercury?

Answer-30: Using if-then-else, e.g., X = (if Y > 0 then "Positive" else "Negative").



Question-31. How do you define a module in Mercury?

Answer-31: Using :- module ModuleName.



Question-32. How do you import a module in Mercury?

Answer-32: Using :- import_module ModuleName.



Question-33. What is the default execution mode in Mercury?

Answer-33: Mercury runs in a strict evaluation mode by default.



Question-34. What is a lambda function in Mercury?

Answer-34: A function defined inline using func(X) = X * X.



Question-35. How do you perform input/output in Mercury?

Answer-35: Using the io module, e.g., io.write_string("Hello", !IO).



Question-36. How does Mercury handle side effects?

Answer-36: Using the io state variable, represented as !IO.



Question-37. How do you read input in Mercury?

Answer-37: Using io.read_line_as_string(Result, !IO).



Question-38. What is the difference between func and pred in Mercury?

Answer-38: func defines a function returning a value, while pred defines predicates with possible multiple solutions.



Question-39. What is tail recursion in Mercury?

Answer-39: A recursive function where the recursive call is the last operation in the function.



Question-40. How does Mercury optimize tail-recursive functions?

Answer-40: Mercury automatically transforms them into loops for better performance.



Question-41. What is backtracking in Mercury?

Answer-41: The ability to explore multiple solutions in a non-deterministic manner.



Question-42. How do you define an accumulator in Mercury?

Answer-42: Using an extra parameter to store computed values across recursive calls.



Question-43. What is a unique mode in Mercury?

Answer-43: di (destructive input) and uo (unique output) enforce single-use references for safety.



Question-44. What is DCG in Mercury?

Answer-44: Definite Clause Grammars (DCG) are used for parsing and grammar representation.



Question-45. How do you implement DCG in Mercury?

Answer-45: Using --> notation in predicate definitions.



Question-46. How do you compile a Mercury program?

Answer-46: Using mmc filename.m.



Question-47. How do you run a Mercury program?

Answer-47: Using ./filename after compiling.



Question-48. What are Mercury's backends?

Answer-48: Mercury supports multiple backends, including C, Java, and .NET.



Question-49. How does Mercury integrate with C?

Answer-49: Using pragma foreign_code and pragma foreign_proc.



Question-50. How do you handle errors in Mercury?

Answer-50: Using require predicates and assertions.




Tags

Frequently Asked Question and Answer on Mercury

Mercury Interview Questions and Answers in PDF form Online

Mercury Questions with Answers

Mercury Trivia MCQ Quiz

FAQ Questions Sidebar

Related Topics


  • API Testing
  • Python
  • AWS Amazon Web Services
  • Java
  • C++
  • JavaScript
  • C#
  • PHP
  • Swift
  • Ruby
  • Kotlin
  • TypeScript
  • Go Golang
  • Rust
  • SQL
  • R
  • MATLAB
  • Perl
  • Scala
  • Dart
  • Haskell
  • Objective-C
  • Shell Scripting Bash
  • Visual Basic VB
  • Lua
  • Groovy
  • F#
  • Julia
  • COBOL
  • Fortran
  • Assembly Language
  • PL/SQL
  • Scratch
  • D
  • Erlang
  • Elixir
  • Clojure
  • Pascal
  • Ada
  • Lisp Common Lisp, Scheme
  • Prolog
  • Apex Salesforce
  • ActionScript
  • ABAP SAP
  • Racket
  • Nim
  • Crystal
  • Smalltalk
  • VHDL
  • Verilog
  • SASS Syntactically Awesome Style Sheets
  • Less CSS Preprocessor
  • CoffeeScript
  • J Sharp
  • Tcl (Tool Command Language)
  • XQuery
  • XSLT
  • OpenCL
  • CUDA
  • OpenGL Shader Language (GLSL)
  • VBScript
  • Solidity (Blockchain/Smart Contracts)
  • Yaml
  • JSON
  • XML
  • GDScript (Godot Engine)
  • UnrealScript (Unreal Engine)
  • Maple
  • Mathematica
  • Max/MSP
  • AutoLISP
  • LabVIEW
  • ScratchJr
  • AWK
  • sed (Stream Editor)
  • PostScript
  • Xojo
  • Q Sharp
  • Ring
  • ActionScript 3
  • OpenEdge ABL
  • RPG (IBM)
  • Inform
  • Modula-3
  • Rebol
  • Tcl/Tk
  • Haxe
  • SML (Standard ML)
  • Eiffel
  • Chapel
  • Red
  • MUMPS
  • PASCAL ABC
  • Icon
  • BCPL
  • Simula
  • SNOBOL
  • Hack (Meta)
  • PowerShell
  • Batch Script
  • AppleScript
  • Glue
  • Oz
  • Io
  • Mercury
  • Wren
  • Genie
  • PureScript
  • MoonScript
  • Turing
  • ALGOL
  • Seed7
  • Kotlin Native
  • Kotlin Multiplatform
  • Elm
  • PureBasic
  • QB64 (QuickBASIC)
  • Nemerle
  • Ocaml
  • Alloy
  • Cobra
  • Forth
  • Ballerina
  • Deno (JavaScript Runtime)
  • WASM (WebAssembly)
  • Z shell (Zsh)
  • Fish Shell
  • Redscript
  • Felix
  • ReScript
  • Agda
  • Idris
  • Coq
  • SPARK
  • Vala
  • PicoLisp
  • Wolfram Language
  • BASH (Bourne Again Shell)
  • Hy (Lisp-like for Python)
  • Terra
  • Boo
  • ATS
  • K (Kdb+)
  • Picat
  • Nimrod
  • Pawn
  • Papyrus (Bethesda Games)
  • J Programming Language
  • X++
  • MQL4/MQL5 (MetaTrader)
  • Transact-SQL (T-SQL)
  • BASH Shell Scripting

More Subjects


  • Computer Fundamentals
  • Data Structure
  • Programming Technologies
  • Software Engineering
  • Artificial Intelligence and Machine Learning
  • Cloud Computing

All Categories


  • Physics
  • Electronics Engineering
  • Electrical Engineering
  • General Knowledge
  • NCERT CBSE
  • Kids
  • History
  • Industry
  • World
  • Computer Science
  • Chemistry

Can't Find Your Question?

If you cannot find a question and answer in the knowledge base, then we request you to share details of your queries to us Suggest a Question for further help and we will add it shortly in our education database.
© 2025 Copyright InterviewQuizz. Developed by Techgadgetpro.com
Privacy Policy