This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn isogram? | |
"An isogram is a word in which no letters occur more than once. | |
Empty string is considered an isogram in this implementation." | |
[^String s] | |
(boolean | |
(when (string? s) | |
(loop [letters (sort (seq s))] | |
(let [[current next & _] letters] | |
(cond | |
(nil? next) true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(System/getProperty "user.dir") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
debugger | |
#dbg | |
#break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; These are equivalent expressions showing how to attempt to access a value: | |
(get {:a \a} :a) | |
({:a \a} :a) | |
(:a {:a \a}) | |
;; These are equivalent ways of trying and supplying a default value: | |
(get {:a \a} :b \b) | |
({:a \a} :b \b) | |
(:b {:a \a} \b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults write com.apple.Finder AppleShowAllFiles true | |
killall Finder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thanks Nick Nichols | |
"Spy Function": { | |
"prefix": "spy", | |
"body": [ | |
"(defn spy [x] (println x) x)" | |
], | |
"description": "Log a value and immediately return it" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Credit, Nick Nichols | |
;; only tested on macOS Big Sur | |
(import '[java.awt.datatransfer DataFlavor StringSelection Transferable]) | |
(defn clipboard [] | |
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit))) | |
(defn clipboard->str | |
[] | |
(.getTransferData (.getContents (clipboard) nil) (DataFlavor/stringFlavor))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Faucet = | |
| Hot | |
| Cold | |
[<EntryPoint>] | |
let main _ = | |
let myFaucet = Cold | |
match myFaucet with | |
| Cold -> 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net5.0</TargetFramework> | |
<NoWarn>0025;</NoWarn> | |
</PropertyGroup> | |
<ItemGroup> | |
<Compile Include="FsAdvent2020.fs" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The 'compare' function from FSharp.Core returns a magic number to indicate the result | |
// compare : 'T -> 'T -> int when 'T : comparison | |
compare 0 1 //-1 | |
compare 0 0 //0 | |
compare 1 0 //1 | |
// We could clarify our intent | |
type Leg = Less | Equal | Greater | |
type Comparer<'T> = 'T -> 'T -> Leg |
NewerOlder