Top Banner
Various Data Types tuple type typ1 * ... * typn F#, OCaml, SML (typ1, ..., typn) Haskell typ1, ..., typn merd tuple Python tuple! Rebol Tuple[Typ1, Typ2, Typ3] E tuple< typ1, ..., typn > C++-0x tuple constructor a, b, c F#, Lua, merd, OCaml, Python, Ruby ( a, b, c ) Ada, C++-0x, Haskell, Perl, Prolog, SML { a. b. c } Smalltalk { a, b, c } Matlab [ a, b, c ] E a . b . c Rebol (cons a b) Common Lisp computable tuple (these are a k ind of immutable lists playing a special role in parameter  passing) empty tuple () merd, Perl, Perl6, Python [] Ruby {} Matlab, Smalltalk #() Smalltalk Nothing Prolog 1-uple a or [a] Ruby a, Perl6, Python tuple([a]) Python (a) Perl ((a)) merd {a} Smalltalk 
23

Various Data Types

May 30, 2018

Download

Documents

polepoleta
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 1/23

Various Data Types

• tuple type

typ1 * ... * typn F#, OCaml, SML

(typ1, ..., typn) Haskelltyp1, ..., typn merd

tuple Python

tuple! Rebol

Tuple[Typ1, Typ2, Typ3] E

tuple< typ1, ..., typn > C++-0x

• tuple constructor 

a, b, c F#, Lua, merd, OCaml, Python, Ruby

( a, b, c ) Ada, C++-0x, Haskell, Perl, Prolog, SML

{ a. b. c } Smalltalk 

{ a, b, c } Matlab

[ a, b, c ] E

a . b . c Rebol

(cons a b) Common Lisp

• computable tuple (these are a kind of immutable lists playing a special role in parameter 

 passing)

empty tuple

() merd, Perl, Perl6, Python

[] Ruby

{} Matlab, Smalltalk 

#() Smalltalk 

Nothing Prolog

1-uple

a or [a] Ruby

a, Perl6, Python

tuple([a]) Python

(a) Perl

((a)) merd

{a} Smalltalk 

Page 2: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 2/23

using a tuple for a function call

t merd, Perl

*t Python, Ruby

t{:} Matlab

f @@ t Mathematica

L =.. [ F | Args ], call(L) Prolog

• reference (pointer)

creation

& B, C, C#, C++

\ Perl

AddressOf Visual Basic

addr(1) Pascal

@(1) Pascal

lv BCPL

ref C#, F#, OCaml, SML

newSTRef Haskell

NewCell Oz

variable Forth

'access Ada

:> :>> Pliant'' Maple

dereference

*(2) B, C, C#, C++

$ @ % &(2) Perl

->[...] ->{...} ->(...)(3) Perl

->(4) C, C++

^(3) Modula-3, Pascal

!(2) F#, OCaml, SML

rv BCPL

readSTRef Haskell

Access Oz

.[all] Ada

@ Forth

Page 3: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 3/23

eval Maple

assigning (when dereferencing doesn't give a lvalue)

Page 4: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 4/23

Page 5: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 5/23

Page 6: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 6/23

Page 7: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 7/23

Page 8: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 8/23

writeSTRef Haskell

Assign Oz

:= F#, OCaml, SML

! Forth

• optional value

null value

0(5) C++, Forth

0 nullptr(5) C++-0x

NULL C, Maple, SQL92nil Common Lisp, Emacs Lisp, Io, Lua, Objective-C, Ruby, Smalltalk 

null C#, Java, JavaScript

Null(6) Ada, Mathematica

undef Perl

None F#, OCaml, Python

NONE SML

Nothing Haskell

Void Eiffel

#f () Emacs Lisp

(empty) / ~ / null YAML

value

Page 9: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 9/23

v Ada, C#, Common Lisp, Eiffel, Emacs Lisp, Java, JavaScript, Lua, Perl, Perl,Python, Ruby, Scheme, Smalltalk 

*v(5) C, C++

Just v Haskell

Some v F#, OCaml

SOME v SML

type name

option F#, OCaml, SML

Maybe Haskell

• record

type declaration

struct { typ1 n1; typ2 n2; ... } C, C++

type typ = { n1 : typ1; n2 : typ2 } OCaml, SML

data Typ = N0 { n1, n2 :: typ1, n3 :: typ3, ... } Haskell

Page 10: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 10/23

type Typ is recordN1 : Typ1;N2 : Typ2 := default_val;...

end record;

Ada

selector 

. Ada, Beta, C, C#, C++, E, Eiffel, F#, Java, JavaScript, Lua, Matlab,Modula-2, Modula-3, OCaml, Oz, Pascal, Python, Ruby

:: XPath

% Fortran90

'(7) Ada

^ Mercury

r { field } merd

r:field Pliantfield r Haskell

-> C, C++

r[field] Maple

r["field"] JavaScript

#field r SML

normal functioncall Common Lisp, Dylan, Haskell, Io, Smalltalk 

• union type declaration

union { typ1 n1; typ2 n2; ... } C, C++

data Typ = N1 typ1 | N2 typ2 | ... Haskell

type typ = N1 of typ1 | N2 of typ2 | ... OCaml

datatype typ = N1 of typ1 | N2 of typ2 | ... SML

type Typ (Choice : Discrete_Type) is recordcase Choice is

when Choice_1 =>N1 : Typ1;

...when Choice_2 | Choice_3 =>

...when others =>

...end case;

end record;

Ada

• enumerated type

Page 11: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 11/23

declaration

adi........

....enum typ { n1; n2; ... }(8) C, C#, C++, Java

Enum typn1n2

End EnumVisual Basic

(n1, n2, ...) Pascal

type typ is(9) Ada

data Typ = N1 | N2 | ... Haskell

type typ = N1 | N2 | ... OCaml

datatype typ = N1 | N2 | ... SML

• dictionary

type name

map YAML

Map F#, Iodict Python

Dictionary Pliant, Smalltalk 

Hash Perl6, Ruby

HASH_TABLE Eiffel

HashTable Java

Page 12: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 12/23

Hashtbl F#

Hashtbl.t OCaml

struct Matlab

table Maple

Data.Map, Data.HashTable Haskell

Containers.Ordered_Maps.Map Ada

constructor 

[ a => b, c => d ] E

array( a => b, c => d ) PHP

{ a => b, c => d } Perl, Perl6, Ruby

{ a, b, c, d } Perl, Ruby

{ a: b, c: d }

JavaScript, Python,

YAML

{ a: b; c: d } CSS

$[ a: b, c: d ] YCP

{ a->b. c->d } Squeak 

{ a = b, c = d } Lua

@{ a = b; c = d } MSH

([ a:b, c:d ]) Pike

([a]=b [c]=d) KornShell<< a b c d >> PostScript

struct(a, b, c, d) Matlab

Hash[ a, b, c, d ] Ruby

Map.of_list [a, b; c, d] F#

Hashtbl.of_list [a, b; c, d] F#

table([a=b, c=d]) Maple

define table foo a => b; c => d end Dylan

dict create a b c d Tcl8.5

new t { {a, b}, {c, d} } C#

fromList Haskell

[NSDictionary dictionaryWithObjectsAndKeys:b, a,d, c, nil] Objective-C

a: b YAML

Page 13: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 13/23

c: d

access: read/write

h[k] Awk, C#, C++, Dylan, E, JavaScript, Lua, Maple, MSH, PHP, Python,Ruby

$h{k} Perl

%h{k} or %h<s> Perl6

$h(k) Tcl

h.[k] F#

h.k JavaScript, Lua, Matlab

h:k Pliant

h["k"] or h->k Pike

(gethash k h) Common Lisp

access: read

h k get PostScript

find F#, OCaml

fetch Ruby

get Java

dict get Tcl8.5

at Io, Smalltalk 

h@k or h.at(k) Eiffel

h[k]:default YCP

${h[k]} KornShell

h.get(k, returned_value_when_k_unfound) Python

objectForKey Objective-C

lookup Haskell

Element Ada

access: writeh k o put PostScript

put Eiffel, Java

add, replace F#, OCaml

store Ruby

dict set Tcl8.5

Page 14: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 14/23

h[k] KornShell, YCP

atPut Io

h at: k put: o Smalltalk 

[h setObject:o forKey:k] Objective-C

insert Haskell

Replace_Element Ada

has the key ?

exists $h{k} Perl

exists Perl6, Pliant

dict exists Tcl8.5

has Eiffel

haskey YCP

hasKey Io

has_key Python

has_key?, include?, key?, member? Ruby

Contains Ada, C#, F#

containsKey Java

includesKey Smalltalk 

k in h JavaScript, Python

k not in h Python

in Awk 

mem F#, OCaml

member Haskell

isfield Matlab

find(10) C++

h[k] Pike

(gethash k h) Common Lispmaps E

known PostScript

isset(h[k]), array_key_exists(k, h) PHP

remove by key

delete $h{k} Perl

Page 15: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 15/23

del h[k] Python

unset(h[k]) PHP

remove Eiffel, F#, Java, OCaml, YCP

Remove C#, F#

dict remove Tcl8.5

removeAt Io

removeKey E, Smalltalk 

remhash Common Lisp

delete Haskell, JavaScript, Perl6, Ruby

Delete Ada

erase C++

m_delete Pike

removeObjectForKey Objective-C

undef PostScript

rmfield Matlab

list of keys

keys Haskell, Io, Maple, MSH, Perl, Perl6, Python,Ruby, Smalltalk 

dict keys Tcl8.5

keySet JavaallKeys Objective-C

AllKeys C#

indices Pike

current_keys Eiffel

getKeys E

array_keys PHP

fieldnames Matlab

findall(Key, item(Key, _),Keys) Prolog

${!h[@]} KornShell

Page 16: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 16/23

list of values

abram

dedy

suparma

n muti

Page 17: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 17/23

arya

 bowo......

...

Page 18: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 18/23

Page 19: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 19/23

adi...........

. values Io, Java, Perl, Perl6, Pike, Python, Ruby, Smalltalk 

dict values Tcl8.5

getValues E

content Eiffel

array_values PHP

struct2cell Matlabentries Maple

elems Haskell

${h[@]} KornShell

merge

merge(11) Ruby

array_merge(11) PHP

union(12) Haskell

update(11) Python, Ruby

putAll(11) Java

insert(12) C++

(%h1, %h2)(11) Perl

• range

inclusive .. inclusive

Page 20: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 20/23

a .. b Ada, E, merd, MSH, Pascal, Perl, Ruby

a:b Matlab

[ a .. b ] F#, Haskell

to Io, Smalltalk 

seq a b / jot - a b(13) BourneShell, FishShell

{a..b} KornShell

range PHP

range(from: a, to: b, by: step) Dylan

Range Mathematica

Range with Io

List.number A B Step Oz

numlist / between Prolog

iseq Logo

inclusive .. exclusive

a ... b Ruby

a ..! b E

range Python

Remarks• (1) Borland extension in Pascal

• (2) prefix

• (3) postfix

• (4) infix

• (5) optional value is only for pointers

• (6) only for "access" types in Ada

• (7) attribute selector 

• (8) Java: introduced in 1.5

• (9) n1, n2, ...

• (10) returns an iterator • (11) right-bias

• (12) left-bias

• (13) jot on BSD

 Pixel 

This document is licensed under GFDL (GNU Free Documentation License).Generated from syntax-across-languages.html.pl 

Page 21: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 21/23

$Id: syntax-across-languages.html.pl 408 2008-08-29 08:32:23Z pixel $

For help about the general syntax of MATLAB functions and commands, type

help syntax

Back to Top of Page Back to TopCommand and Function Syntaxes

You can enter MATLAB commands using either a command or function syntax. It is important to learnthe restrictions and interpretation rules for both.

functionname arg1 arg2 arg3 % Command syntaxfunctionname('arg1','arg2','arg3') % Function syntax

For more information: See Calling Functions in the MATLAB Programming Fundamentalsdocumentation.

Back to Top of Page Back to TopCommand Line Continuation

You can continue most statements to one or more additional lines by terminating each incomplete line

with an ellipsis (...). Breaking down a statement into a number of lines can sometimes result in a clearer  programming style.

sprintf ('Example %d shows a command coded on %d lines.\n', ...exampleNumber, ...numberOfLines)

 Note that you cannot continue an incomplete string to another line.

disp 'This statement attempts to continue a string ...to another line, resulting in an error.'

For more information: See Entering Long Statements in the MATLAB Desktop Tools and DevelopmentEnvironment documentation.

Back to Top of Page Back to TopCompleting Commands Using the Tab Key

You can save some typing when entering commands by entering only the first few letters of thecommand, variable, property, etc. followed by the Tab key. Typing the second line below (with T

Page 22: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 22/23

representing Tab) yields the expanded, full command shown in the third line:

f = figure;set(f, 'papTuT,'cT) % Type this line.set(f, 'paperunits','centimeters') % This is what you get.

If there are too many matches for the string you are trying to complete, you will get no response fromthe first Tab. Press Tab again to see all possible choices:

set(f, 'paTTPaperOrientation PaperPositionMode PaperType ParentPaperPosition PaperSize PaperUnits

For more information: See Tab Completion in the Command Window in the MATLAB Desktop Toolsand Development Environment documentation

Back to Top of Page Back to TopRecalling Commands

Use any of the following methods to simplify recalling previous commands to the screen:

*

To recall an earlier command to the screen, press the up arrow key one or more times, until you seethe command you want. If you want to modify the recalled command, you can edit its text before pressing Enter or Return to execute it.

*

To recall a specific command by name without having to scroll through your earlier commands one by one, type the starting letters of the command, followed by the up arrow key.

*

Open the Command History window (Desktop > Command History) to see all previous commands.Double-click the command you want to execute.

For more information: See Recalling Previous Lines and Command History Window in the MATLABDesktop Tools and Development Environment documentation.

Back to Top of Page Back to TopClearing Commands

If you have typed a command that you then decide not to execute, you can clear it from the CommandWindow by pressing the Escape (Esc) key.

Back to Top of Page Back to TopSuppressing Output to the Screen

To suppress output to the screen, end statements with a semicolon. This can be particularly useful whengenerating large matrices.

Page 23: Various Data Types

8/9/2019 Various Data Types

http://slidepdf.com/reader/full/various-data-types 23/23

A = magic(100); % Create matrix A, but do not display it.

Back to Top of Page Back to Top Was this topic helpful?

Introduction Introduction Help Help

Recommended Products

* MATLAB* Signal Processing Toolbox* Optimization Toolbox* Statistics Toolbox* Control System Toolbox

Get MATLAB trial software

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLABexperts.

Get the Interac