Right, the first link I posted above has info on how to use app passwords, etc. Although, that seems to only be necessary if two factor is enabled.
Is there way to car
a string or pattern match a string’s head and rest? e.g. (car "string")
You can use string-ref
.
Consider using string->list
then work on the list instead.
@samth it can get head of string, but how to get rest of string?
I found there is function called string->immutable-string
, but it still a string. (no car/head cdr/tail function provided)
@soegaard2 This works, thanks.
@chansey97 (define (car-str str)
(substring str 0 1))
(define (cdr-str str)
(substring str 1))
@badkins no i dont have two factor enabled
@zenspider how did you create an app specific password?
@badkins yes, but it can not be pattern matched.
Why not?
I would also suggest that usually processing strings character-by-character is not the right approach — string-ref
(and similarly substring
and string->list
) doesn’t handle more complicated cases like combining characters.
sorry, I am not familiar with pattern matching. But you provide two functions, so we must use if else to check the return value.
Are you wanting something like Haskell’s pattern match on x:xs for strings?
@badkins yes It would be nice, if we can do (match some-string
[()
......]
[(x xs)
......])
I wouldn’t be surprised if you’re able to create a custom matcher to handle what you want, but I’d probably just use: (cond [(empty-string? str) ... ]
[else ... ])
You can do: (match s
[(app list->string (list)) ...]
[(app list->string (cons x xs)) ...])
they can only be used with two factor authentication accounts
eeewww :slightly_smiling_face:
You can also do: (define-match-expander str (syntax-rules () [(_ p) (app list->string p)]))
(match s
[(str (list)) ...]
[(str (cons x xs)) ...])
@samth In your first example, the x and xs are bounded? it is surprising! Could you give me some referece of app
? I’m sorry, the keyword app
is not friendly to search engine.
But again, I want to encourage you to think about whether character-by-character processing is really the right thing. For example, what is the first character in ":jp:"?
Because the result from string-ref
is #\🇯
@samth Yes, finally will preprocess the string by using list->string
, and use list instead.
I’m guessing @samth meant string->list
above
yes
@badkins yes.
just typo..
@samth I am just writing a toy parser by functional way in racket, I don’t want to use cursor for the position of the string.
@samth What do you mean by For example, what is the first character in ":jp:"? Does string->list
support unicode?
What do you mean by “support unicode”? string-length
of that string produces 2.
Flags (and many other emoji) are made up of multiple combining characters.
@samth OK, that’s not a problem.
@samth but wait, Does Emoji and Unicode overlap? For example:
Is this unicode?
yes, all the characters you see anywhere are unicode
:grinning: <— this is emoji from Slack
yes, and it’s a unicode character
OMG! emojis are exactly unicode characters? I did not know before…
well, “character” is a complicated concept, and some emoji (like that flag) are made up of multiple characters (in some senses)
But I copy this face in slack, it give me ": grinning :"
that’s how you can type it in slack
@samth I used to think emoji were just ASCII characters, and the text renderer parse these characters between ::. Thank you for telling me this knowledge!
I copied a japanese flag from https://emojipedia.org/flag-japan/ to Emacs.
It return 2
.
It’s amazing.
In slack, we just type :jp: