The Mercury Frequently Asked Questions List

Similar documents
The Prolog to Mercury transition guide

Introduction to Programming Using Java (98-388)

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

The Mercury User s Guide

Runtime support for region-based memory management in Mercury

CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM

Introduction to C++ with content from

Ch. 7: Control Structures

CSE 361S Intro to Systems Software Final Project

Practical C Issues:! Preprocessor Directives, Multi-file Development, Makefiles. CS449 Fall 2017

Starting to Program in C++ (Basics & I/O)

CS558 Programming Languages

The Mercury project. Zoltan Somogyi

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

Hardening LLVM with Random Testing

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

2012 LLVM Euro - Michael Spencer. lld. Friday, April 13, The LLVM Linker

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

CS : Programming for Non-majors, Summer 2007 Programming Project #2: Census Due by 12:00pm (noon) Wednesday June

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Motivation was to facilitate development of systems software, especially OS development.

Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

GCC: the GNU Compiler Collection

Side Effects (3A) Young Won Lim 1/13/18

GCC: the GNU Compiler Collection

Vector and Free Store (Pointers and Memory Allocation)

Products and Records

Program Design: Using the Debugger

Lecture 10: building large projects, beginning C++, C++ and structs

The Prolog to Mercury transition guide

MPLAB XC8 C Compiler Version 2.00 Release Notes for AVR MCU

Motivation was to facilitate development of systems software, especially OS development.

Annotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

Typed Racket: Racket with Static Types

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

The Typed Racket Guide

What do Compilers Produce?

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

C - Basics, Bitwise Operator. Zhaoguo Wang

Declaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:

2 Compiling a C program

Hacking in C. Pointers. Radboud University, Nijmegen, The Netherlands. Spring 2019

Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder

Class Information ANNOUCEMENTS

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Libgdb. Version 0.3 Oct Thomas Lord

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Binghamton University. CS-211 Fall Variable Scope

CAAM 420 Daily Note. Scriber: Qijia Jiang. Date: Oct.16. Project 3 Due Wed 23.Oct. Two parts: debug code and library exercise.

Increases Program Structure which results in greater reliability. Polymorphism

Preventing and Finding Bugs in Parallel Programs

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Lecture 2: SML Basics

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

PHP 1. Introduction Temasek Polytechnic

1. Allowed you to see the value of one or more variables, or 2. Indicated where you were in the execution of a program

8 Understanding Subtyping

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

COSC 2P91. Bringing it all together... Week 4b. Brock University. Brock University (Week 4b) Bringing it all together... 1 / 22

Principles of Programming Languages. Objective-C. Joris Kluivers

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

CS240: Programming in C

THE TOOLS OF THE TRADE

Storage class in C. Automatic variables External variables Static variables Register variables Scopes and longevity of above types of variables.

Semantic Analysis. Lecture 9. February 7, 2018

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

CS 314 Principles of Programming Languages. Lecture 9

Java is an objet-oriented programming language providing features that support

Software Design and Analysis for Engineers

Name, Scope, and Binding. Outline [1]

Dynamic Memory Allocation

Recap. Recap. If-then-else expressions. If-then-else expressions. If-then-else expressions. If-then-else expressions

EW The Source Browser might fail to start data collection properly in large projects until the Source Browser window is opened manually.

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

VARIABLES AND TYPES CITS1001

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Incremental Linking with Gold

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

ENERGY 211 / CME 211. Evolution

Submitted to the Onward track of OOPSLA-03 ABSTRACT. Keywords

What s NetBeans? Like Eclipse:

Lecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii.

Debugging. ICS312 Machine-Level and Systems Programming. Henri Casanova

Introduction to C An overview of the programming language C, syntax, data types and input/output

Lecture 2: C Programming Basic

Names, Scope, and Bindings

Packing sub-word-size arguments. Zoltan Somogyi

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.

CSE 230 Intermediate Programming in C and C++ Functions

Text Input and Conditionals

GNU ccscript Scripting Guide IV

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

Transcription:

The Mercury Frequently Asked Questions List Version 14.01.1 Fergus Henderson Thomas Conway Zoltan Somogyi

Copyright c 1995 1997,1999,2001 2014 The University of Melbourne. Permission is granted to make and distribute verbatim copies of this FAQ list provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this FAQ list under the conditions for verbatim copying, provided also that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this FAQ list into another language, under the above conditions for modified versions.

i Table of Contents 1 Problems during compilation and installation.................................................. 1 2 Common programming errors................. 1 3 Problems caused by unimplemented Mercury features......................................... 3 4 What to do when all else fails................. 3

Chapter 2: Common programming errors 1 1 Problems during compilation and installation. 1. The compiler crashes during the make install phase Mercury s use of GNU C extensions can cause problems with some versions of GCC, notably versions 4.2 and 4.3. Either use a different version of GCC, or configure Mercury so that it does not require any GNU C extensions. The following describes how to do the latter. For versions of Mercury after 0.13.1, invoke the configure script with the option --with-llds-base-grade=none. This will cause the compiler to be built in the none.gc grade, which does not use any GNU C extensions. The configure script for Mercury version 0.13.1 (and before) does not support the above option. Instead create a file in the top-level directory of the unpacked source tree named Mmake.params containing the line GRADE=none.gc. After running the configure script, do make and make install as normal. 2. The make install phase takes ages! What s going on? Mercury supports many grades. A grade is a combination the target language and feature options. These features include garbage collection, debugging and profiling support. See Grades and grade components in the User s Guide. During the make install phase the newly built compiler is used to compile the standard library in each of the selected grades. The runtime system is also rebuilt for each grade. To install fewer grades and reduce the time make install takes, see the configure script s options, in particular --disable-most-grades. Alternatively, run make install LIBGRADES=<grades> instead, where <grades> is a space-separated list of grades. Users of Mac OS X should note that there appear to be performance problems with the linker on some versions of that operating system that can lead to excessive linking times with code generated by the Mercury compiler. 2 Common programming errors 1. What does the error message undefined symbol. /2 mean? You need to explicitly import the list module :- import_module list. if your code uses lists. Similarly, if your code uses arithmetic operations, you will need to import the int and possibly float modules. 2. Why doesn t X <= 3 work? In Mercury, less-than-or-equal-to is written as =< not as <=, which is used for reverse implication.

Chapter 2: Common programming errors 2 3. I defined a type like this: :- type number ---> int ; float. Why doesn t this work? You tried to define a type that is an undiscriminated union of two types, which is not allowed by the Mercury type system. The declaration above defines an enumerated type with two constants, int and float. This is not what you want, but it is legal Mercury, which is why you don t get an error message on the type declaration itself. 4. I get a scope error in an if-then-else. I checked and both branches bind the same variables. What is the error? This error generally happens if you attempt bind non-local variables in the condition of the if-then-else. For example, the following code attempts to bind Value in the call to map.search, but Value occurs outside of the if-then-else in particular, it occurs in the head of the clause. :- pred map.search(map(k, V), K, V). :- mode map.search(in, in, out) is semidet. :- pred lookup(map(string, int), string, int). :- mode lookup(in, in, out) is det. lookup(map, Key, Value) :- (if map.search(map, Key, Value) then true else Value = -1 ). Binding non-local variables in the condition of an if-then-else is forbidden since it would be unsound; it would lead to inconsistent results. For example, (X = 1 -> Y = 1 ; Y = 2), X = 2 would fail, but X = 2, (X = 1 -> Y = 1 ; Y = 2) would succeed breaking one of the fundamental laws of logic, (P, Q) <=> (Q, P). Mode analysis therefore rejects such programs. (In certain rare circumstances, the compiler may report this as a mode error rather than a scope error.) The way to fix such errors is to avoid binding non-local variables in the condition, and instead bind them in the then part of the if-then-else. So in the above example, you should introduce a new local variable, which we will call Value1 : lookup(map, Key, Value) :- ( map.search(map, Key, Value1) -> Value = Value1 ; Value = -1 ). 5. I keep getting a link error undefined symbol init_gc. Why?

Chapter 4: What to do when all else fails 3 If you are using mmake to recompile your program, and you are overriding the default grade (e.g. by setting GRADE=asm_fast in your Mmake file), you must make sure that you do mmake clean every time you change grades. 3 Problems caused by unimplemented Mercury features 1. How can I avoid getting a compile-time error when I try to fill in a partially instantiated data structure? At the moment, you can create a partially instantiated data structure, but you can t fill in the holes. The reason is that the code that does the filling in must temporarily alias two variables together, and the current mode checker does not allow this. This limitation will go away in the future. 2. I m getting an error from the C compiler: foo.c:45: initializer is not computable at load time You re using an old version of gcc. Check that the version of gcc in your PATH is version 2.6.3 or later. Mercury does not (at the current time) support versions of gcc earlier than 2.6.3. (Using the --no-static-ground-terms option may also solve this problem, but results in less efficient code.) 4 What to do when all else fails 1. I m getting an error message that I don t understand. What can I do? Try compiling with the -E ( --verbose-error-messages ) option. This option causes the compiler to give even more verbose descriptions than usual. 2. I followed the instructions in the user s guide, but it still didn t work. What do I do next? Send email to bugs@mercurylang.org, and we ll try to solve your problem.