Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 02 04:10
    jchud13 closed #106
  • Mar 02 04:10
    jchud13 commented #106
  • Mar 02 04:02
    whacked commented #106
  • Mar 02 03:15
    jchud13 opened #106
  • Sep 05 2019 11:30
  • Sep 05 2019 11:29
    madelinekosse synchronize #105
  • Sep 05 2019 11:12
  • Sep 05 2019 11:11
    thisdotrob synchronize #105
  • Apr 23 2019 09:57
  • Apr 23 2019 09:56
    thisdotrob synchronize #105
  • Apr 18 2019 09:09
  • Apr 18 2019 09:08
    thisdotrob synchronize #105
  • Apr 17 2019 14:08
  • Apr 17 2019 14:06
    thisdotrob synchronize #105
  • Apr 03 2019 11:00
  • Apr 03 2019 10:59
    thisdotrob edited #105
  • Apr 03 2019 10:59
    thisdotrob opened #105
  • Dec 02 2018 01:02
    francescoagati commented #104
  • Dec 02 2018 01:02
    francescoagati closed #104
  • Nov 30 2018 23:19
    francescoagati commented #104
aeolus8
@aeolus8
Hello I am trying to take in an array of strings and count how many times a string in the array appears in the array (confusing) for example if there is string[] { "hello", "hi", "hi", "hello", "hi"} I would like to be able to print out hello 2, hi 3
@sleepyfox
@sleepyfox
Try this @aeolus8
(var strings (list 'hello 'hi 'hi 'hello 'hi)) 
(def count-items (acc, x) (if (get acc x) (do (set acc x (+ 1 (get acc x))) acc) (do (set acc x 1) acc)))
(.reduce strings count-items (hash))
aeolus8
@aeolus8
@sleepyfox Wow I don't think I would have figured out something this clean. thank you I appreciate it! Do you know if there is a sort method for a hash? I think I want to present the highest occurring string first.
@sleepyfox
@sleepyfox
Object properties have no intrinsic ordering, so first you need to convert the object to an array of tuples, one for each entry. Then sort that array using a custom function that compares the second element of the tuples. Simples!
P.S. Don't worry that this isn't obvious, there's a kind of mental gymnastics at work in solving programming problems, you get better with practice.
Michael Klarman
@mklarman
Hello all. I have a few questions on sibiliant. Can anyone help me?
Fred Daoud
@foxdonut
@mklarman what are your questions?
Michael Klarman
@mklarman
how do you push an item to an array?
what is the syntax for it?
Fred Daoud
@foxdonut
(append ["a" "b"] "c")
Michael Klarman
@mklarman
cool
Fred Daoud
@foxdonut
result: [ 'a', 'b', 'c' ]
Michael Klarman
@mklarman
How about for a loop in a loop?
Fred Daoud
@foxdonut
Depends, what are you trying to achieve?
Michael Klarman
@mklarman
i want to iterate through an array and push to a new array all items just one time getting rid of all doubles, then I want to loop New Array and loop orig array and count the number of times the item appears and save that number
how do you start a new project once you've downloaded sibilant?
Fred Daoud
@foxdonut
The first question is probably a good one for @sleepyfox :wink:
Fred Daoud
@foxdonut
For the second question, it depends on your build tools...
hello-sibilant just compiles one file
sibilant-mithril-seview compiles all the files and bundles them with browserify
@sleepyfox
@sleepyfox
@mklarman depends, are you deploying to Nodejs or the browser?
"getting rid of all doubles" sounds like a set. Counting occurrences sounds very much like the previous answer I gave on Mar 29 with the count-items function. Can you give us an example to make it clearer what you're trying to do?
Michael Klarman
@mklarman
is anyone here?
Fred Daoud
@foxdonut
hello
Michael Klarman
@mklarman
hi
I have been asked to do a small project in sibilant. How can I test my code other than in the sibilant console? Will it work on a webpage like js? How can I start a project in sibilant? What are the file extensions?
aeolus8
@aeolus8
@sleepyfox Thank you for all the advice and info. I'm coming from a back-end c# experience and I dont work with this or even JS. Very confusing syntax in my opinion
@sleepyfox
@sleepyfox
@aeolus8 I'm guessing you've never done any LISP before? Because basically there is no syntax apart from S-expressions...

@CharlesSPatterson AFAIK append still works. Alternatively you can use something like:

(var my-list (list 1 2 3))
(my-list.push 4)

Remember that lists are just JS Arrays, so all of your normal Array methods work.

@sleepyfox
@sleepyfox
@mklarman you might want to check out https://github.com/sleepyfox/sibilant-starter
@sleepyfox
@sleepyfox
^^I've just pushed a change that updates out-of-date old dependencies.
Fred Daoud
@foxdonut
@mklarman if you scroll up you will see that I gave you two examples.
Karthik Rumalla
@ronaldo1769
@sleepyfox Can you please tell me how to code custom sorting to sort hashmap based on values? Thank you.
Michael Klarman
@mklarman
if I have an array [1 7 100 3] and I do the .sort function on it, it returns [1 100 3 7]. Why?
@sleepyfox
@sleepyfox
@mklarman Because JS has the default sort for arrays being alphabetical - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort - this catches out most people who are new to JS.
@sleepyfox
@sleepyfox
@ronaldo1769 See the above MDN link, you simply need to supply a sort function to the sort method, for example: (.sort [1 7 100 3] (# (a b) (- a b)))
(for a numeric sort in ascending order)
francesco agati
@francescoagati
hello there is a mode for have hygienic macros in sibilant?
francesco agati
@francescoagati
ok resolved sorry
i have see scoped-without-source
francesco agati
@francescoagati
hello there is a mode for reload a file inside repl
the files and macro are cached
@sleepyfox
@sleepyfox
Hi @francescoagati - not as far as I'm aware - although it's supposed to be possible to delete from the require cache I can't actually get it to work in node:current :-(
francesco agati
@francescoagati
@sleepyfox thanks
Alexander Vega
@Unimplied
Hey everyone, I was wondering if sibilant had comparison operators? I'm trying to compare to values in two separate lists, but keep getting an unexpected token exception.
Jacob Rothstein
@jbr
Sibilant does have comparison operators like <, <=, > & >=. They’re prefix not infix, like (< a b)
Jared Chudzinski
@jchud13
Hello everyone! I need a bit of help,
How can I do something like var count = seen[input]; in sibilant?
Jared Chudzinski
@jchud13
Found help on github forums thank you for your time