User-Defined Operators: Overview and Benefits

undefined
 
Adám Brudzewsky
 
User-Defined Operators
 
 
 
 
 
 
Overview
 
 
Why?
 
What?
 
How?
 
Examples
 
 
Overview
 
 
 
Apply multiple functions in similar ways
Add a parameter to tweak behaviour
Achieve nicer looking expressions
Amend primitives to your needs
Avoid repeating yourself
 
 
Why define your own operators?
 
 
Apply multiple functions in similar ways
Add a parameter to tweak behaviour
Achieve nicer looking expressions
Amend primitives to your needs
Avoid repeating yourself
… in ways that isn't part of the core language
 
 
Why define your own operators?
 
 
F
/
 
 
F
.
G
∨.∧
 
⌊.
×
 
+
.
=
 
-.
÷
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
 
 
F
/
+
/
 
×
/
 
,
/
 
/
 
F
.
G
.
 
.
×
 
+
.
=
 
-
.
÷
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
 
 
F
/
+
/
 
×
/
 
,
/
 
/
 
F
.
G
.
 
.
×
 
+
.
=
 
-
.
÷
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
operand
 
 
F
/
+
/
 
×
/
 
,
/
 
/
 
F
.
G
.
 
.
×
 
+
.
=
 
-
.
÷
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
function
operand
 
 
+
/
 
×
 
,
\
 
 
.
 
@
×
 
+
=
 
-
÷
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
function
operand
 
 
42
 
1200
 
3
 
1
+
 
'Hi'
R
'Hello'
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
array
operand
 
 
42
 
1200
 
3
 
1
+
 
'Hi'
R
'Hello'
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
derived
functions
 
 
Answer
 ← 42
Format
 ← 1200
 
Replace
 ← 'Hi'
R
'Hello'
Increment
 ← 1
+
Windows
3
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
derived
functions
 
Answer
 ← 42
 
⍝ ambivalent
Format
 ← 1200
 
⍝ dyadic
 
Replace
 ← 'Hi'
R
'Hello'
 
⍝ ambivalent
Increment
 ← 1
+
 
⍝ monadic
Windows
3
 
⍝ monadic
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
derived
functions
 
Answer
 ← 42
 
ambivalent
Format
 ← 1200
 
⍝ dyadic
 
Replace
 ← 'Hi'
R'Hello'
 
⍝ ambivalent
Increment
 ← 1
+
 
⍝ monadic
Windows
⊢⌺
3
 
⍝ monadic
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
derived
functions
 
Answer
 ← 42
 
⍝ ambivalent
Format
 ← 1200
 
dyadic
 
Replace
 ← 'Hi'
R'Hello'
 
⍝ ambivalent
Increment
 ← 1
+
 
⍝ monadic
Windows
⊢⌺
3
 
⍝ monadic
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
derived
functions
 
Answer
 ← 42
 
⍝ ambivalent
Format
 ← 1200
 
⍝ dyadic
 
Replace
 ← 'Hi'
R'Hello'
 
⍝ ambivalent
Increment
 ← 1
+
 
monadic
Windows
⊢⌺
3
 
⍝ monadic
 
 
What is an operator?
 
MONADIC
OPERATOR
 
DYADIC
OPERATOR
derived
functions
 
 
What is an operator?
 
TRAD
 
FN
Calling syntax in header
 res←x Name y
  res←x y
 
D
 
FN
Presence of 
 and 
 in body
Name←{
    
 
}
 
 
How are they defined/identified?
 
dyadic function
 
TRAD
 
OP
Calling syntax in header
 res←(F Name)y
  res←F y
 
D
 
OP
Presence of 
⍺⍺
 or 
⍵⍵
 in body
Name←{
    
⍺⍺
 
}
 
 
How are they defined/identified?
 
monadic operator deriving a monadic function
 
TRAD
 
OP
Calling syntax in header
 res←x(F Name)y
  res←x F y
 
D
 
OP
Presence of 
⍺⍺
 or 
⍵⍵
 in body
Name←{
    
 
⍺⍺
 
}
 
 
How are they defined/identified?
 
monadic operator deriving a dyadic function
 
TRAD
 
OP
Calling syntax in header
 res←x(F Name G)y
  res←x F G y
 
D
 
OP
Presence of 
⍺⍺
 or 
⍵⍵
 in body
Name←{
    
 
⍺⍺
 
⍵⍵
 
}
 
 
How are they defined/identified?
 
dyadic operator deriving a dyadic function
 
TRAD
 
OP
Calling syntax in header
 res←(F Name G)y
  res←F G y
 
D
 
OP
Presence of 
⍺⍺
 or 
⍵⍵
 in body
Name←{
    
⍺⍺
 
⍵⍵
 
}
 
 
How are they defined/identified?
 
dyadic operator deriving a monadic function
 
 
Apply multiple functions in similar ways
Add a parameter to tweak behaviour
Achieve nicer looking expressions
Amend primitives to your needs
Avoid repeating yourself
 
 
 
 
_S←{
 
(
 
⍺⍺
 
)}  
 Stack
Vowel←
∊∘
'AEIOU'
Vowel _S 
A
'AEIOU'
_S
A
 
_T←{
 
 r←
 
⍺⍺
 
 
 
(62
ATX '
⍺⍺
')
 '→'r 
 r}  
 Trace
-_T/3 1 4 1 5
 
 
Demo: utilities
 
 
A_←{
(
⍵⍵
 
⍺⍺
 
⍵⍵⍨
)
}  
 Across
'HELLO'
_A_~'APL'
 
_H_←{(
⍺⍺
 
)
⍵⍵
 
}  
 Hook
_H_≡¨'hello' 'racecar' 'APL' 'ABBA' 'max'
_H_≡¨_S'hello' 'racecar' 'APL' 'ABBA' 'max'
_H_≡¨_H_/'hello' 'racecar' 'APL' 'ABBA' 'max'
 
 
Demo: combinators/compositions
 
 
 
 param Fn _W_ Cond initArg
_W_←{
 
 
⍵⍵
 
:
 
 
 
⍺⍺
 
 
 
}  
 While
2×_W_{
<100}4
2×_T _W_{
<100}4
 
_E_←{
 
 0::
 
⍵⍵
 
 
 
 
⍺⍺
 
}  
 ErrorElse
 
_0←{r←
 
 (
r)←
⍺⍺
¨
r 
 r}  
 Depth 0
(×/
)_0 4 5(2 3)
 
Demo: thought concepts
 
June 23:
 
TBA
 
 
 
 
Next Webinar
 
June 23:
 
TBA
 
Remember:
 
BAA webinars every other week
britishaplassociation.org/webinar-schedule-2022
June 16
th
, 30
th
; July 14
th
, 28
th
; etc.
 
 
 
Next Webinar
 
June 23:
 
TBA
 
Remember:
 
BAA webinars every other week
britishaplassociation.org/webinar-schedule-2022
June 16
th
, 30
th
; July 14
th
, 28
th
; etc.
 
More at:
 
apl.wiki/activities
 
 
Next Webinar
Slide Note
Embed
Share

In this comprehensive guide, delve into the world of user-defined operators, exploring the reasons behind defining your own operators and understanding what operators are. Discover the advantages of custom operators and how they can enhance functionality, aesthetics, and efficiency in programming. Uncover the core concepts and practical examples to solidify your understanding and proficiency in this advanced topic.

  • Operators
  • User-Defined
  • Programming
  • Customization
  • Functions

Uploaded on Feb 22, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. User-Defined Operators Ad m Brudzewsky

  2. Overview User-Defined Operators 1

  3. Overview Why? What? How? Examples User-Defined Operators 2

  4. Why define your own operators? Apply multiple functions in similar ways Add a parameter to tweak behaviour Achieve nicer looking expressions Amend primitives to your needs Avoid repeating yourself User-Defined Operators 3

  5. Why define your own operators? Apply multiple functions in similar ways Add a parameter to tweak behaviour Achieve nicer looking expressions Amend primitives to your needs Avoid repeating yourself in ways that isn't part of the core language User-Defined Operators 4

  6. What is an operator? F/ F.G . . +.= -. User-Defined Operators 5

  7. What is an operator? F/ / +/ / ,/ F.G . . +.= -. User-Defined Operators 6

  8. What is an operator? operand F/ / +/ / ,/ F.G . . +.= -. User-Defined Operators 7

  9. What is an operator? F/ / +/ / ,/ function operand F.G . . +.= -. User-Defined Operators 8

  10. What is an operator? +/ ,\ function operand . @ + = - User-Defined Operators 9

  11. What is an operator? 42 1200 array operand 3 1 + 'Hi' R'Hello' User-Defined Operators 10

  12. What is an operator? derived functions 42 1200 3 1 + 'Hi' R'Hello' User-Defined Operators 11

  13. What is an operator? derived functions Answer 42 Format 1200 Replace 'Hi' R'Hello' Increment 1 + Windows 3 User-Defined Operators 12

  14. What is an operator? derived functions Answer 42 Format 1200 ambivalent dyadic Replace 'Hi' R'Hello' Increment 1 + Windows 3 ambivalent monadic monadic User-Defined Operators 13

  15. What is an operator? derived functions Answer 42 Format 1200 ambivalent dyadic 'a' Answer 'b' 42 Answer 'b' 42 Replace 'Hi' R'Hello' Increment 1 + Windows 3 ambivalent monadic monadic User-Defined Operators 14

  16. What is an operator? derived functions Answer 42 Format 1200 Format 123 SYNTAX ERROR: The function requires a left argument Format 123 ambivalent dyadic Replace 'Hi' R'Hello' Increment 1 + Windows 3 ambivalent monadic monadic User-Defined Operators 15

  17. What is an operator? derived functions 4 Increment 2 SYNTAX ERROR: The function does not take a left argument 4 Increment 2 Answer 42 Format 1200 ambivalent dyadic Replace 'Hi' R'Hello' Increment 1 + Windows 3 ambivalent monadic monadic User-Defined Operators 16

  18. What is an operator? FUNCTION deriving a monadic dyadic ambivalent OPERATOR monadic 1200 42 +\ dyadic 3 , 2 +. User-Defined Operators 17

  19. How are they defined/identified? TRADFN DFN Presence of and in body Calling syntax in header res x Name y res x y Name { } dyadic function User-Defined Operators 18

  20. How are they defined/identified? TRADOP DOP Presence of or in body Calling syntax in header res (F Name)y res F y Name { } monadic operator deriving a monadic function User-Defined Operators 19

  21. How are they defined/identified? TRADOP DOP Presence of or in body Calling syntax in header res x(F Name)y res x F y Name { } monadic operator deriving a dyadic function User-Defined Operators 20

  22. How are they defined/identified? TRADOP DOP Presence of or in body Calling syntax in header res x(F Name G)y res x F G y Name { } dyadic operator deriving a dyadic function User-Defined Operators 21

  23. How are they defined/identified? TRADOP DOP Presence of or in body Calling syntax in header res (F Name G)y res F G y Name { } dyadic operator deriving a monadic function User-Defined Operators 22

  24. Apply multiple functions in similar ways Add a parameter to tweak behaviour Achieve nicer looking expressions Amend primitives to your needs Avoid repeating yourself User-Defined Operators 23

  25. Demo: utilities _S { ( )} Stack Vowel 'AEIOU' Vowel _S A 'AEIOU' _S A _T { r (62 ATX ' ') ' 'r r} Trace -_T/3 1 4 1 5 User-Defined Operators 24

  26. Demo: combinators/compositions A_ { ( ) } Across 'HELLO' _A_~'APL' _H_ {( ) } Hook _H_ 'hello' 'racecar' 'APL' 'ABBA' 'max' _H_ _S'hello' 'racecar' 'APL' 'ABBA' 'max' _H_ _H_/'hello' 'racecar' 'APL' 'ABBA' 'max' User-Defined Operators 25

  27. Demo: thought concepts param Fn _W_ Cond initArg _W_ { : } While 2 _W_{ <100}4 2 _T _W_{ <100}4 _E_ { 0:: } ErrorElse _0 {r ( r) r r} Depth 0 ( / )_0 4 5(2 3) User-Defined Operators 26

  28. Next Webinar June 23: TBA User-Defined Operators 27

  29. Next Webinar June 23: TBA Remember: BAA webinars every other week britishaplassociation.org/webinar-schedule-2022 June 16th, 30th; July 14th, 28th; etc. User-Defined Operators 28

  30. Next Webinar June 23: TBA Remember: BAA webinars every other week britishaplassociation.org/webinar-schedule-2022 June 16th, 30th; July 14th, 28th; etc. More at: apl.wiki/activities User-Defined Operators 29

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#