Measures Concepts
GitHub icon

Directives

Directives - language feature

< >
Example from JavaScript, TypeScript:
"use strict"; "use asm";
Example from Python, Cython:
from __future__ import feature # coding=<encoding name>
Example from C, C++, Objective-C, Tick C:
#include <stdio.h> #define height 10 #ifdef #endif #if #else #ifndef #undef #pragma
Example from Perl:
# In Perl, the keyword "use", which imports modules, can also be used to specify directives, such as use strict; or use utf8; use utf8;
Example from Ruby:
coding: UTF-8
Example from C#:
#define MAX_CLIENTS 200 int array[MAX_CLIENTS]; #if PRODUCTION //code #elif DEVELOPMENT //code #else //code #endif
Example from Rust:
// A conditionally-compiled module #[cfg(target_os = "linux")] mod bar { /* ... */ } // General metadata applied to the enclosing module or crate. #![crate_type = "lib"] // A function marked as a unit test #[test] fn test_foo() { /* ... */ } // A lint attribute used to suppress a warning/error #[allow(non_camel_case_types)] type int8_t = i8; // Inner attribute applies to the entire function. fn some_unused_variables() { #![allow(unused_variables)] let x = (); let y = (); let z = (); }
Example from Haskell:
{-# INLINE foo #-}
Example from Visual Basic:
Option Explicit On|Off Option Compare Binary
Example from Erlang:
-define(TIMEOUT, 200). ... call(Request) -> server:call(refserver, Request, ?TIMEOUT). -undef(Macro).
Example from F#:
#if VERSION1 let function1 x y = printfn "x: %d y: %d" x y x + 2 * y #else let function1 x y = printfn "x: %d y: %d" x y x - 2*y #endif // Line directives as source maps can be used when compiling to F#: #line 25 "C:\\Projects\\MyProject\\MyProject\\Script1"
Example from ALGOL 68, Mary:
.PR POINT .PR .PR UPPER .PR .PR RES .PR 'pr' quote 'pr'
Example from FML:
# Directives are special lines that have syntax and semantics of their own. Directives all start with a name of the form .foo; new directives may be added by future versions of the language. .import math.constants area = x * math.constants.Pi, ^ 2 .from math.constants import Pi, E area = x sq, * Pi polar = a * [E ^ [b * 0+j1]]

Languages with Directives include JavaScript, Python, C, C++, Perl, Ruby, C#, Ada, Rust, Haskell, TypeScript, Objective-C, Visual Basic, Erlang, F#, Common Lisp, Cython, ALGOL 68, Jule, C2, Mary, FML, ScriptEase, Tick C

Languages without Directives include C3, progsbase

This question asks: Is the language embedded in a tiny compile-time directive language?

Read more about Directives on the web: 1.

HTML of this page generated by Features.ts

View source

- Build the next great programming language Search Add Language Features Creators Resources About Blog Acknowledgements Queries Stats Sponsor Day 605 feedback@pldb.io Logout